[gtkmm-documentation] Update examples with Gtk::DrawingArea



commit 871847ffcef4445a54d7a656d90c3cb794fc1167
Author: Kjell Ahlstedt <kjell ahlstedt bredband net>
Date:   Thu Nov 24 13:50:32 2016 +0100

    Update examples with Gtk::DrawingArea
    
    Use set_draw_func() instead of signal_draw().connect() or on_draw() override.

 examples/book/aspectframe/examplewindow.cc         |    3 ++-
 examples/book/custom/custom_widget/mywidget.h      |    2 +-
 .../dialogs/colorchooserdialog/examplewindow.cc    |    7 ++-----
 .../dialogs/colorchooserdialog/examplewindow.h     |    4 +++-
 examples/book/drawingarea/arcs/myarea.cc           |   18 +++++-------------
 examples/book/drawingarea/arcs/myarea.h            |    5 +----
 examples/book/drawingarea/clock/clock.cc           |    9 ++-------
 examples/book/drawingarea/clock/clock.h            |    6 +-----
 examples/book/drawingarea/curve/myarea.cc          |   11 ++---------
 examples/book/drawingarea/curve/myarea.h           |    5 +----
 examples/book/drawingarea/image/myarea.cc          |   18 +++++++++---------
 examples/book/drawingarea/image/myarea.h           |    3 +--
 examples/book/drawingarea/joins/myarea.cc          |   11 ++---------
 examples/book/drawingarea/joins/myarea.h           |    5 +----
 examples/book/drawingarea/pango_text/myarea.cc     |    9 ++-------
 examples/book/drawingarea/pango_text/myarea.h      |    3 +--
 examples/book/drawingarea/simple/myarea.cc         |   11 ++---------
 examples/book/drawingarea/simple/myarea.h          |    5 +----
 examples/book/drawingarea/thin_lines/myarea.cc     |   12 ++++--------
 examples/book/drawingarea/thin_lines/myarea.h      |    3 +--
 examples/book/flowbox/examplewindow.cc             |   10 +++++-----
 examples/book/flowbox/examplewindow.h              |    5 +++--
 examples/book/printing/advanced/previewdialog.cc   |    9 ++++-----
 examples/book/printing/advanced/previewdialog.h    |    3 +--
 examples/book/toolpalette/canvas.cc                |    8 +++-----
 examples/book/toolpalette/canvas.h                 |    4 +---
 26 files changed, 61 insertions(+), 128 deletions(-)
---
diff --git a/examples/book/aspectframe/examplewindow.cc b/examples/book/aspectframe/examplewindow.cc
index 44659d4..5e72772 100644
--- a/examples/book/aspectframe/examplewindow.cc
+++ b/examples/book/aspectframe/examplewindow.cc
@@ -28,7 +28,8 @@ ExampleWindow::ExampleWindow()
   // Add a child widget to the aspect frame */
   // Ask for a 200x200 window, but the AspectFrame will give us a 200x100
   // window since we are forcing a 2x1 aspect ratio */
-  m_DrawingArea.set_size_request(200, 200);
+  m_DrawingArea.set_content_width(200);
+  m_DrawingArea.set_content_height(200);
   m_AspectFrame.add(m_DrawingArea);
   m_AspectFrame.property_margin() = 10;
 
diff --git a/examples/book/custom/custom_widget/mywidget.h b/examples/book/custom/custom_widget/mywidget.h
index 84f4e31..2eac98c 100644
--- a/examples/book/custom/custom_widget/mywidget.h
+++ b/examples/book/custom/custom_widget/mywidget.h
@@ -38,7 +38,7 @@ protected:
   void on_unmap() override;
   void on_realize() override;
   void on_unrealize() override;
-  bool on_draw(const Cairo::RefPtr<Cairo::Context>& cr) override;
+  bool on_draw(const Cairo::RefPtr<Cairo::Context>& cr) /* override */;
 
   //Signal handler:
   void on_parsing_error(const Glib::RefPtr<const Gtk::CssSection>& section, const Glib::Error& error);
diff --git a/examples/book/dialogs/colorchooserdialog/examplewindow.cc 
b/examples/book/dialogs/colorchooserdialog/examplewindow.cc
index bdf0f23..49248b0 100644
--- a/examples/book/dialogs/colorchooserdialog/examplewindow.cc
+++ b/examples/book/dialogs/colorchooserdialog/examplewindow.cc
@@ -42,8 +42,7 @@ ExampleWindow::ExampleWindow()
   m_ColorButton.set_rgba(m_Color);
 
   m_VBox.pack_start(m_DrawingArea);
-  m_DrawingArea.signal_draw().connect(sigc::mem_fun(*this,
-    &ExampleWindow::on_drawing_area_draw));
+  m_DrawingArea.set_draw_func(sigc::mem_fun(*this, &ExampleWindow::on_drawing_area_draw));
 
   show_all_children();
 }
@@ -91,10 +90,8 @@ void ExampleWindow::on_button_dialog_clicked()
   }
 }
 
-bool ExampleWindow::on_drawing_area_draw(const Cairo::RefPtr<Cairo::Context>& cr)
+void ExampleWindow::on_drawing_area_draw(const Cairo::RefPtr<Cairo::Context>& cr, int, int)
 {
   Gdk::Cairo::set_source_rgba(cr, m_Color);
   cr->paint();
-
-  return true;
 }
diff --git a/examples/book/dialogs/colorchooserdialog/examplewindow.h 
b/examples/book/dialogs/colorchooserdialog/examplewindow.h
index d1d848b..4253071 100644
--- a/examples/book/dialogs/colorchooserdialog/examplewindow.h
+++ b/examples/book/dialogs/colorchooserdialog/examplewindow.h
@@ -29,7 +29,9 @@ protected:
   //Signal handlers:
   void on_color_button_color_set();
   void on_button_dialog_clicked();
-  bool on_drawing_area_draw(const Cairo::RefPtr<Cairo::Context>& cr);
+
+  //Draw function:
+  void on_drawing_area_draw(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height);
 
   //Child widgets:
   Gtk::Box m_VBox;
diff --git a/examples/book/drawingarea/arcs/myarea.cc b/examples/book/drawingarea/arcs/myarea.cc
index 503bce8..2ba3924 100644
--- a/examples/book/drawingarea/arcs/myarea.cc
+++ b/examples/book/drawingarea/arcs/myarea.cc
@@ -1,5 +1,3 @@
-//$Id: myarea.cc 836 2007-05-09 03:02:38Z jjongsma $ -*- c++ -*-
-
 /* gtkmm example Copyright (C) 2002 gtkmm development team
  *
  * This program is free software; you can redistribute it and/or modify
@@ -22,24 +20,20 @@
 
 MyArea::MyArea()
 {
+  set_draw_func(sigc::mem_fun(*this, &MyArea::on_draw));
 }
 
 MyArea::~MyArea()
 {
 }
 
-bool MyArea::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
+void MyArea::on_draw(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height)
 {
-  // This is where we draw on the window
-  Gtk::Allocation allocation = get_allocation();
-  const int width = allocation.get_width();
-  const int height = allocation.get_height();
-  const int lesser = MIN(width, height);
+  const int lesser = std::min(width, height);
 
   // coordinates for the center of the window
-  int xc, yc;
-  xc = width / 2;
-  yc = height / 2;
+  const int xc = width / 2;
+  const int yc = height / 2;
 
   cr->set_line_width(lesser * 0.02);  // outline thickness changes
                                       // with window size
@@ -83,6 +77,4 @@ bool MyArea::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
   cr->fill_preserve();
   cr->restore();  // back to opaque black
   cr->stroke();
-
-  return true;
 }
diff --git a/examples/book/drawingarea/arcs/myarea.h b/examples/book/drawingarea/arcs/myarea.h
index 7642930..b17dde7 100644
--- a/examples/book/drawingarea/arcs/myarea.h
+++ b/examples/book/drawingarea/arcs/myarea.h
@@ -1,5 +1,3 @@
-//$Id: myarea.h 491 2005-12-23 11:01:49Z murrayc $ -*- c++ -*-
-
 /* gtkmm example Copyright (C) 2002 gtkmm development team
  *
  * This program is free software; you can redistribute it and/or modify
@@ -28,8 +26,7 @@ public:
   virtual ~MyArea();
 
 protected:
-  //Override default signal handler:
-  bool on_draw(const Cairo::RefPtr<Cairo::Context>& cr) override;
+  void on_draw(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height);
 };
 
 #endif // GTKMM_EXAMPLE_MYAREA_H
diff --git a/examples/book/drawingarea/clock/clock.cc b/examples/book/drawingarea/clock/clock.cc
index 3900fbb..198d29d 100644
--- a/examples/book/drawingarea/clock/clock.cc
+++ b/examples/book/drawingarea/clock/clock.cc
@@ -26,18 +26,15 @@ Clock::Clock()
 : m_radius(0.42), m_line_width(0.05)
 {
   Glib::signal_timeout().connect( sigc::mem_fun(*this, &Clock::on_timeout), 1000 );
+  set_draw_func(sigc::mem_fun(*this, &Clock::on_draw));
 }
 
 Clock::~Clock()
 {
 }
 
-bool Clock::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
+void Clock::on_draw(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height)
 {
-  Gtk::Allocation allocation = get_allocation();
-  const int width = allocation.get_width();
-  const int height = allocation.get_height();
-
   // scale to unit square and translate (0, 0) to be (0.5, 0.5), i.e.
   // the center of the window
   cr->scale(width, height);
@@ -121,8 +118,6 @@ bool Clock::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
   // draw a little dot in the middle
   cr->arc(0, 0, m_line_width / 3.0, 0, 2 * M_PI);
   cr->fill();
-
-  return true;
 }
 
 
diff --git a/examples/book/drawingarea/clock/clock.h b/examples/book/drawingarea/clock/clock.h
index 3764ef4..8f766e3 100644
--- a/examples/book/drawingarea/clock/clock.h
+++ b/examples/book/drawingarea/clock/clock.h
@@ -1,5 +1,3 @@
-//$Id: clock.h 491 2005-12-23 11:01:49Z murrayc $ -*- c++ -*-
-
 /* gtkmm example Copyright (C) 2002 gtkmm development team
  *
  * This program is free software; you can redistribute it and/or modify
@@ -28,14 +26,12 @@ public:
   virtual ~Clock();
 
 protected:
-  //Override default signal handler:
-  bool on_draw(const Cairo::RefPtr<Cairo::Context>& cr) override;
+  void on_draw(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height);
 
   bool on_timeout();
 
   double m_radius;
   double m_line_width;
-
 };
 
 #endif // GTKMM_EXAMPLE_CLOCK_H
diff --git a/examples/book/drawingarea/curve/myarea.cc b/examples/book/drawingarea/curve/myarea.cc
index 5d82e18..a6b2ea8 100644
--- a/examples/book/drawingarea/curve/myarea.cc
+++ b/examples/book/drawingarea/curve/myarea.cc
@@ -1,5 +1,3 @@
-//$Id: myarea.cc 491 2005-12-23 11:01:49Z murrayc $ -*- c++ -*-
-
 /* gtkmm example Copyright (C) 2002 gtkmm development team
  *
  * This program is free software; you can redistribute it and/or modify
@@ -21,18 +19,15 @@
 
 MyArea::MyArea()
 {
+  set_draw_func(sigc::mem_fun(*this, &MyArea::on_draw));
 }
 
 MyArea::~MyArea()
 {
 }
 
-bool MyArea::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
+void MyArea::on_draw(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height)
 {
-  Gtk::Allocation allocation = get_allocation();
-  const int width = allocation.get_width();
-  const int height = allocation.get_height();
-
   double x0=0.1, y0=0.5, // start point
          x1=0.4, y1=0.9,  // control point #1
          x2=0.6, y2=0.1,  // control point #2
@@ -53,6 +48,4 @@ bool MyArea::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
   cr->move_to(x2, y2);
   cr->line_to (x3, y3);
   cr->stroke();
-
-  return true;
 }
diff --git a/examples/book/drawingarea/curve/myarea.h b/examples/book/drawingarea/curve/myarea.h
index 7642930..b17dde7 100644
--- a/examples/book/drawingarea/curve/myarea.h
+++ b/examples/book/drawingarea/curve/myarea.h
@@ -1,5 +1,3 @@
-//$Id: myarea.h 491 2005-12-23 11:01:49Z murrayc $ -*- c++ -*-
-
 /* gtkmm example Copyright (C) 2002 gtkmm development team
  *
  * This program is free software; you can redistribute it and/or modify
@@ -28,8 +26,7 @@ public:
   virtual ~MyArea();
 
 protected:
-  //Override default signal handler:
-  bool on_draw(const Cairo::RefPtr<Cairo::Context>& cr) override;
+  void on_draw(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height);
 };
 
 #endif // GTKMM_EXAMPLE_MYAREA_H
diff --git a/examples/book/drawingarea/image/myarea.cc b/examples/book/drawingarea/image/myarea.cc
index eec8eee..46960bc 100644
--- a/examples/book/drawingarea/image/myarea.cc
+++ b/examples/book/drawingarea/image/myarea.cc
@@ -40,27 +40,27 @@ MyArea::MyArea()
 
   // Show at least a quarter of the image.
   if (m_image)
-    set_size_request(m_image->get_width()/2, m_image->get_height()/2);
+  {
+    set_content_width(m_image->get_width()/2);
+    set_content_height(m_image->get_height()/2);
+  }
+
+  // Set the draw function.
+  set_draw_func(sigc::mem_fun(*this, &MyArea::on_draw));
 }
 
 MyArea::~MyArea()
 {
 }
 
-bool MyArea::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
+void MyArea::on_draw(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height)
 {
   if (!m_image)
-    return false;
-
-  Gtk::Allocation allocation = get_allocation();
-  const int width = allocation.get_width();
-  const int height = allocation.get_height();
+    return;
 
   // Draw the image in the middle of the drawing area, or (if the image is
   // larger than the drawing area) draw the middle part of the image.
   Gdk::Cairo::set_source_pixbuf(cr, m_image,
     (width - m_image->get_width())/2, (height - m_image->get_height())/2);
   cr->paint();
-
-  return true;
 }
diff --git a/examples/book/drawingarea/image/myarea.h b/examples/book/drawingarea/image/myarea.h
index 9f12545..522f5a9 100644
--- a/examples/book/drawingarea/image/myarea.h
+++ b/examples/book/drawingarea/image/myarea.h
@@ -27,8 +27,7 @@ public:
   virtual ~MyArea();
 
 protected:
-  //Override default signal handler:
-  bool on_draw(const Cairo::RefPtr<Cairo::Context>& cr) override;
+  void on_draw(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height);
 
   Glib::RefPtr<Gdk::Pixbuf> m_image;
 };
diff --git a/examples/book/drawingarea/joins/myarea.cc b/examples/book/drawingarea/joins/myarea.cc
index ed49ca9..d4a2cad 100644
--- a/examples/book/drawingarea/joins/myarea.cc
+++ b/examples/book/drawingarea/joins/myarea.cc
@@ -1,5 +1,3 @@
-//$Id: myarea.cc 836 2007-05-09 03:02:38Z jjongsma $ -*- c++ -*-
-
 /* gtkmm example Copyright (C) 2002 gtkmm development team
  *
  * This program is free software; you can redistribute it and/or modify
@@ -21,22 +19,19 @@
 
 MyArea::MyArea()
 {
+  set_draw_func(sigc::mem_fun(*this, &MyArea::on_draw));
 }
 
 MyArea::~MyArea()
 {
 }
 
-bool MyArea::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
+void MyArea::on_draw(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height)
 {
   // This is where we draw on the window
   auto window = get_window();
   if(window)
   {
-    Gtk::Allocation allocation = get_allocation();
-    const int width = allocation.get_width();
-    const int height = allocation.get_height();
-
     cr->set_line_width(10.0);
 
     // Scale to unit square
@@ -62,6 +57,4 @@ bool MyArea::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
     cr->set_line_join(Cairo::LINE_JOIN_ROUND);
     cr->stroke();
   }
-
-  return true;
 }
diff --git a/examples/book/drawingarea/joins/myarea.h b/examples/book/drawingarea/joins/myarea.h
index 7642930..b17dde7 100644
--- a/examples/book/drawingarea/joins/myarea.h
+++ b/examples/book/drawingarea/joins/myarea.h
@@ -1,5 +1,3 @@
-//$Id: myarea.h 491 2005-12-23 11:01:49Z murrayc $ -*- c++ -*-
-
 /* gtkmm example Copyright (C) 2002 gtkmm development team
  *
  * This program is free software; you can redistribute it and/or modify
@@ -28,8 +26,7 @@ public:
   virtual ~MyArea();
 
 protected:
-  //Override default signal handler:
-  bool on_draw(const Cairo::RefPtr<Cairo::Context>& cr) override;
+  void on_draw(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height);
 };
 
 #endif // GTKMM_EXAMPLE_MYAREA_H
diff --git a/examples/book/drawingarea/pango_text/myarea.cc b/examples/book/drawingarea/pango_text/myarea.cc
index 9d4738c..dd9a299 100644
--- a/examples/book/drawingarea/pango_text/myarea.cc
+++ b/examples/book/drawingarea/pango_text/myarea.cc
@@ -18,18 +18,15 @@
 
 MyArea::MyArea()
 {
+  set_draw_func(sigc::mem_fun(*this, &MyArea::on_draw));
 }
 
 MyArea::~MyArea()
 {
 }
 
-bool MyArea::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
+void MyArea::on_draw(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height)
 {
-  Gtk::Allocation allocation = get_allocation();
-  const int width = allocation.get_width();
-  const int height = allocation.get_height();
-
   const int rectangle_width = width;
   const int rectangle_height = height / 2;
 
@@ -59,8 +56,6 @@ bool MyArea::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
   // black text
   cr->set_source_rgb(0.0, 0.0, 0.0);
   draw_text(cr, rectangle_width, rectangle_height);
-
-  return true;
 }
 
 void MyArea::draw_rectangle(const Cairo::RefPtr<Cairo::Context>& cr,
diff --git a/examples/book/drawingarea/pango_text/myarea.h b/examples/book/drawingarea/pango_text/myarea.h
index 822e471..2f0d0a9 100644
--- a/examples/book/drawingarea/pango_text/myarea.h
+++ b/examples/book/drawingarea/pango_text/myarea.h
@@ -26,8 +26,7 @@ public:
   virtual ~MyArea();
 
 protected:
-  //Override default signal handler:
-  bool on_draw(const Cairo::RefPtr<Cairo::Context>& cr) override;
+  void on_draw(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height);
 
 private:
   void draw_rectangle(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height);
diff --git a/examples/book/drawingarea/simple/myarea.cc b/examples/book/drawingarea/simple/myarea.cc
index 99d1ee2..4f04b97 100644
--- a/examples/book/drawingarea/simple/myarea.cc
+++ b/examples/book/drawingarea/simple/myarea.cc
@@ -1,5 +1,3 @@
-//$Id: myarea.cc 491 2005-12-23 11:01:49Z murrayc $ -*- c++ -*-
-
 /* gtkmm example Copyright (C) 2002 gtkmm development team
  *
  * This program is free software; you can redistribute it and/or modify
@@ -21,18 +19,15 @@
 
 MyArea::MyArea()
 {
+  set_draw_func(sigc::mem_fun(*this, &MyArea::on_draw));
 }
 
 MyArea::~MyArea()
 {
 }
 
-bool MyArea::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
+void MyArea::on_draw(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height)
 {
-  Gtk::Allocation allocation = get_allocation();
-  const int width = allocation.get_width();
-  const int height = allocation.get_height();
-
   // coordinates for the center of the window
   int xc, yc;
   xc = width / 2;
@@ -48,6 +43,4 @@ bool MyArea::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
   cr->move_to(xc, yc);
   cr->line_to(width, yc);
   cr->stroke();
-
-  return true;
 }
diff --git a/examples/book/drawingarea/simple/myarea.h b/examples/book/drawingarea/simple/myarea.h
index 7642930..b17dde7 100644
--- a/examples/book/drawingarea/simple/myarea.h
+++ b/examples/book/drawingarea/simple/myarea.h
@@ -1,5 +1,3 @@
-//$Id: myarea.h 491 2005-12-23 11:01:49Z murrayc $ -*- c++ -*-
-
 /* gtkmm example Copyright (C) 2002 gtkmm development team
  *
  * This program is free software; you can redistribute it and/or modify
@@ -28,8 +26,7 @@ public:
   virtual ~MyArea();
 
 protected:
-  //Override default signal handler:
-  bool on_draw(const Cairo::RefPtr<Cairo::Context>& cr) override;
+  void on_draw(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height);
 };
 
 #endif // GTKMM_EXAMPLE_MYAREA_H
diff --git a/examples/book/drawingarea/thin_lines/myarea.cc b/examples/book/drawingarea/thin_lines/myarea.cc
index 6d3fd55..d4a8d75 100644
--- a/examples/book/drawingarea/thin_lines/myarea.cc
+++ b/examples/book/drawingarea/thin_lines/myarea.cc
@@ -19,19 +19,17 @@
 MyArea::MyArea()
 : m_fix (0)
 {
-  set_size_request (200, 100);
+  set_content_width(200);
+  set_content_height(100);
+  set_draw_func(sigc::mem_fun(*this, &MyArea::on_draw));
 }
 
 MyArea::~MyArea()
 {
 }
 
-bool MyArea::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
+void MyArea::on_draw(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height)
 {
-  Gtk::Allocation allocation = get_allocation();
-  const int width = allocation.get_width();
-  const int height = allocation.get_height();
-
   cr->set_line_width(1.0);
 
   // draw one line, every two pixels
@@ -44,8 +42,6 @@ bool MyArea::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
   }
 
   cr->stroke();
-
-  return true;
 }
 
 // Toogle between both values (0 or 0.5)
diff --git a/examples/book/drawingarea/thin_lines/myarea.h b/examples/book/drawingarea/thin_lines/myarea.h
index 00a2a6d..c4d9cf2 100644
--- a/examples/book/drawingarea/thin_lines/myarea.h
+++ b/examples/book/drawingarea/thin_lines/myarea.h
@@ -29,8 +29,7 @@ public:
   void force_redraw();
 
 protected:
-  //Override default signal handler:
-  bool on_draw(const Cairo::RefPtr<Cairo::Context>& cr) override;
+  void on_draw(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height);
 
 private:
   double m_fix;
diff --git a/examples/book/flowbox/examplewindow.cc b/examples/book/flowbox/examplewindow.cc
index 84bc80a..00a2136 100644
--- a/examples/book/flowbox/examplewindow.cc
+++ b/examples/book/flowbox/examplewindow.cc
@@ -55,22 +55,22 @@ Gtk::Button* ExampleWindow::create_color_swatch(int swatch_i)
   auto drawing_area = Gtk::manage(new Gtk::DrawingArea());
   auto color_swatch = Gtk::manage(new Gtk::Button());
 
-  drawing_area->set_size_request(24, 24);
+  drawing_area->set_content_width(24);
+  drawing_area->set_content_height(24);
 
   color_swatch->add(*drawing_area);
-  drawing_area->signal_draw().connect(sigc::bind(sigc::mem_fun(*this,
+  drawing_area->set_draw_func(sigc::bind(sigc::mem_fun(*this,
     &ExampleWindow::on_drawing_area_draw), swatch_i));
 
   return color_swatch;
 }
 
-bool ExampleWindow::on_drawing_area_draw(const Cairo::RefPtr<Cairo::Context>& cr, int swatch_i)
+void ExampleWindow::on_drawing_area_draw(const Cairo::RefPtr<Cairo::Context>& cr,
+  int, int, int swatch_i)
 {
   Gdk::RGBA rgba(m_color_names[swatch_i]);
   Gdk::Cairo::set_source_rgba(cr, rgba);
   cr->paint();
-
-  return true;
 }
 
 void ExampleWindow::fill_color_names()
diff --git a/examples/book/flowbox/examplewindow.h b/examples/book/flowbox/examplewindow.h
index 14a1008..b5fae23 100644
--- a/examples/book/flowbox/examplewindow.h
+++ b/examples/book/flowbox/examplewindow.h
@@ -28,8 +28,9 @@ public:
   virtual ~ExampleWindow();
 
 protected:
-  //Signal handlers:
-  bool on_drawing_area_draw(const Cairo::RefPtr<Cairo::Context>& cr, int swatch_i);
+  // Draw function
+  void on_drawing_area_draw(const Cairo::RefPtr<Cairo::Context>& cr,
+    int width, int height, int swatch_i);
 
   // Containers
   Gtk::ScrolledWindow m_scrolled_window;
diff --git a/examples/book/printing/advanced/previewdialog.cc 
b/examples/book/printing/advanced/previewdialog.cc
index 70aacb6..98836e6 100644
--- a/examples/book/printing/advanced/previewdialog.cc
+++ b/examples/book/printing/advanced/previewdialog.cc
@@ -45,7 +45,8 @@ PreviewDialog::PreviewDialog(
   m_HBox.pack_start(m_CloseButton, Gtk::PACK_SHRINK);
   m_VBox.pack_start(m_HBox, Gtk::PACK_SHRINK);
 
-  m_DrawingArea.set_size_request(200, 300);
+  m_DrawingArea.set_content_width(200);
+  m_DrawingArea.set_content_height(300);
   m_VBox.pack_start(m_DrawingArea, Gtk::PACK_EXPAND_WIDGET);
 
   m_refPreview->signal_ready().connect(
@@ -57,7 +58,7 @@ PreviewDialog::PreviewDialog(
   m_DrawingArea.signal_realize().connect(
     sigc::mem_fun(*this, &PreviewDialog::on_drawing_area_realized));
 
-  m_DrawingArea.signal_draw().connect(
+  m_DrawingArea.set_draw_func(
     sigc::mem_fun(*this, &PreviewDialog::on_drawing_area_draw));
 
   m_CloseButton.signal_clicked().connect(
@@ -92,7 +93,7 @@ void PreviewDialog::on_page_number_changed()
   m_DrawingArea.queue_draw();
 }
 
-bool PreviewDialog::on_drawing_area_draw(const Cairo::RefPtr<Cairo::Context>& cr)
+void PreviewDialog::on_drawing_area_draw(const Cairo::RefPtr<Cairo::Context>& cr, int, int)
 {
   Cairo::RefPtr<Cairo::Context> prev_cairo_ctx;
   double dpi_x = 72.0;
@@ -111,8 +112,6 @@ bool PreviewDialog::on_drawing_area_draw(const Cairo::RefPtr<Cairo::Context>& cr
 
   if(m_refPrintContext)
     m_refPrintContext->set_cairo_context(prev_cairo_ctx, dpi_x, dpi_y);
-
-  return true;
 }
 
 void PreviewDialog::on_popreview_ready(const Glib::RefPtr<Gtk::PrintContext>&)
diff --git a/examples/book/printing/advanced/previewdialog.h b/examples/book/printing/advanced/previewdialog.h
index 9b2fda7..f89da4e 100644
--- a/examples/book/printing/advanced/previewdialog.h
+++ b/examples/book/printing/advanced/previewdialog.h
@@ -36,7 +36,7 @@ protected:
 
   void on_hide() override;
 
-  bool on_drawing_area_draw(const Cairo::RefPtr<Cairo::Context>& cr);
+  void on_drawing_area_draw(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height);
 
   //PrintOperationPreview signal handlers:
   void on_popreview_ready(const Glib::RefPtr<Gtk::PrintContext>& print_ctx);
@@ -47,7 +47,6 @@ protected:
   Glib::RefPtr<Gtk::PrintOperationPreview> m_refPreview;
   Glib::RefPtr<Gtk::PrintContext> m_refPrintContext;
   Glib::RefPtr<Pango::Layout> m_refLayout;
-  // Gdk::DrawingContext is new in gtkmm 3.22 (and 3.21.x, where x > 2)
   Glib::RefPtr<Gdk::DrawingContext> m_refDrawingContext;
 
   Gtk::Box m_VBox;
diff --git a/examples/book/toolpalette/canvas.cc b/examples/book/toolpalette/canvas.cc
index 2cb444a..761aada 100644
--- a/examples/book/toolpalette/canvas.cc
+++ b/examples/book/toolpalette/canvas.cc
@@ -21,6 +21,7 @@ Canvas::Canvas()
 : m_drag_data_requested_for_drop(false),
   m_drop_item(nullptr)
 {
+  set_draw_func(sigc::mem_fun(*this, &Canvas::on_draw));
 }
 
 Canvas::~Canvas()
@@ -56,11 +57,10 @@ void Canvas::item_draw(const CanvasItem *item,
     cr->paint();
 }
 
-bool Canvas::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
+void Canvas::on_draw(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height)
 {
   cr->set_source_rgb(1.0, 1.0, 1.0);
-  const Gtk::Allocation allocation = get_allocation();
-  cr->rectangle(0, 0, allocation.get_width(), allocation.get_height());
+  cr->rectangle(0, 0, width, height);
   cr->fill();
 
   for(type_vec_items::iterator iter = m_canvas_items.begin();
@@ -71,8 +71,6 @@ bool Canvas::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
 
   if(m_drop_item)
     item_draw (m_drop_item, cr, true);
-
-  return true;
 }
 
 
diff --git a/examples/book/toolpalette/canvas.h b/examples/book/toolpalette/canvas.h
index 84073cc..a1035c7 100644
--- a/examples/book/toolpalette/canvas.h
+++ b/examples/book/toolpalette/canvas.h
@@ -1,5 +1,3 @@
-//$Id: examplewindow.h 705 2006-07-19 02:55:32Z jjongsma $ -*- c++ -*-
-
 /* gtkmm example Copyright (C) 2002 gtkmm development team
  *
  * This program is free software; you can redistribute it and/or modify
@@ -58,7 +56,7 @@ private:
     const Cairo::RefPtr<Cairo::Context>& cr,
     bool preview);
 
-  bool on_draw(const Cairo::RefPtr<Cairo::Context>& cr) override;
+  void on_draw(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height);
   void on_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context,
     int x, int y, const Gtk::SelectionData& selection_data, guint info, guint time) override;
   bool on_drag_motion(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, guint time) override;


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