[gtkmm-documentation] examples: Don't use removed Gdk::Surface::invalidate_rect()



commit cdf457405fc33ba41a2232630179c813cb4cccd9
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date:   Mon Apr 29 16:22:06 2019 +0200

    examples: Don't use removed Gdk::Surface::invalidate_rect()
    
    Use Gtk::Widget::queue_draw() instead of Gdk::Surface::invalidate_rect().
    Use Gtk::CssSection::get_[start|end]_location() instead of
    get_[start|end]_[line|position]().
    Use Gtk::Widget::get_parent()+get_surface() instead of get_parent_surface().
    The replaced methods have been removed from gtkmm4.

 examples/book/custom/custom_widget/mywidget.cc | 28 +++++++++-----------------
 examples/book/drawingarea/clock/clock.cc       | 13 +++---------
 examples/book/drawingarea/thin_lines/myarea.cc | 14 ++-----------
 examples/book/drawingarea/thin_lines/myarea.h  |  1 -
 examples/others/calendar/calendar.cc           | 25 +++++++----------------
 5 files changed, 21 insertions(+), 60 deletions(-)
---
diff --git a/examples/book/custom/custom_widget/mywidget.cc b/examples/book/custom/custom_widget/mywidget.cc
index 7db4940..fcb3c4c 100644
--- a/examples/book/custom/custom_widget/mywidget.cc
+++ b/examples/book/custom/custom_widget/mywidget.cc
@@ -16,6 +16,7 @@
 
 #include "mywidget.h"
 #include <gdkmm/general.h>  // for cairo helper functions
+#include <gtkmm/container.h>
 #include <gtkmm/snapshot.h>
 #include <iostream>
 //#include <gtk/gtkwidget.h> //For GTK_IS_WIDGET()
@@ -59,20 +60,7 @@ MyWidget::MyWidget() :
   m_refCssProvider->signal_parsing_error().connect(
     sigc::mem_fun(*this, &MyWidget::on_parsing_error));
 
-  try
-  {
-    m_refCssProvider->load_from_path("custom_gtk.css");
-  }
-  catch(const Gtk::CssProviderError& ex)
-  {
-    std::cerr << "CssProviderError, Gtk::CssProvider::load_from_path() failed: "
-              << ex.what() << std::endl;
-  }
-  catch(const Glib::Error& ex)
-  {
-    std::cerr << "Error, Gtk::CssProvider::load_from_path() failed: "
-              << ex.what() << std::endl;
-  }
+  m_refCssProvider->load_from_path("custom_gtk.css");
 }
 
 MyWidget::~MyWidget()
@@ -145,7 +133,7 @@ void MyWidget::on_realize()
   if(!m_refGdkSurface)
   {
     //Create the GdkSurface:
-    m_refGdkSurface = Gdk::Surface::create_child(get_parent_surface(), get_allocation());
+    m_refGdkSurface = Gdk::Surface::create_child(get_parent()->get_surface(), get_allocation());
     set_surface(m_refGdkSurface);
 
     // Make the widget receive expose events
@@ -214,9 +202,11 @@ void MyWidget::on_parsing_error(const Glib::RefPtr<const Gtk::CssSection>& secti
       std::cerr << "  URI = " << file->get_uri() << std::endl;
     }
 
-    std::cerr << "  start_line = " << section->get_start_line()+1
-              << ", end_line = " << section->get_end_line()+1 << std::endl;
-    std::cerr << "  start_position = " << section->get_start_position()
-              << ", end_position = " << section->get_end_position() << std::endl;
+    auto start_location = section->get_start_location();
+    auto end_location = section->get_end_location();
+    std::cerr << "  start_line = " << start_location.get_lines()+1
+              << ", end_line = " << end_location.get_lines()+1 << std::endl;
+    std::cerr << "  start_position = " << start_location.get_line_chars()
+              << ", end_position = " << end_location.get_line_chars() << std::endl;
   }
 }
diff --git a/examples/book/drawingarea/clock/clock.cc b/examples/book/drawingarea/clock/clock.cc
index 603677a..4135f6f 100644
--- a/examples/book/drawingarea/clock/clock.cc
+++ b/examples/book/drawingarea/clock/clock.cc
@@ -118,16 +118,9 @@ void Clock::on_draw(const Cairo::RefPtr<Cairo::Context>& cr, int width, int heig
   cr->fill();
 }
 
-
 bool Clock::on_timeout()
 {
-    // force our program to redraw the entire clock.
-    auto surface = get_surface();
-    if (surface)
-    {
-        Gdk::Rectangle rect(0, 0, get_allocation().get_width(),
-                get_allocation().get_height());
-        surface->invalidate_rect(rect);
-    }
-    return true;
+  // force our program to redraw the entire clock.
+  queue_draw();
+  return true;
 }
diff --git a/examples/book/drawingarea/thin_lines/myarea.cc b/examples/book/drawingarea/thin_lines/myarea.cc
index 368820d..22fd374 100644
--- a/examples/book/drawingarea/thin_lines/myarea.cc
+++ b/examples/book/drawingarea/thin_lines/myarea.cc
@@ -50,16 +50,6 @@ void MyArea::fix_lines(bool fix)
   // to get the width right, we have to draw in the middle of the pixel
   m_fix = fix ? 0.5 : 0.0;
 
-  force_redraw();
-}
-
-// force the redraw of the image
-void MyArea::force_redraw()
-{
-  auto surface = get_surface();
-  if (surface)
-  {
-    Gdk::Rectangle rect(0, 0, get_allocation().get_width(), get_allocation().get_height());
-    surface->invalidate_rect(rect);
-  }
+  // force the redraw of the image
+  queue_draw();
 }
diff --git a/examples/book/drawingarea/thin_lines/myarea.h b/examples/book/drawingarea/thin_lines/myarea.h
index c4d9cf2..01c3924 100644
--- a/examples/book/drawingarea/thin_lines/myarea.h
+++ b/examples/book/drawingarea/thin_lines/myarea.h
@@ -26,7 +26,6 @@ public:
   virtual ~MyArea();
 
   void fix_lines(bool fix = true);
-  void force_redraw();
 
 protected:
   void on_draw(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height);
diff --git a/examples/others/calendar/calendar.cc b/examples/others/calendar/calendar.cc
index dffa71c..3bdec4f 100644
--- a/examples/others/calendar/calendar.cc
+++ b/examples/others/calendar/calendar.cc
@@ -128,20 +128,7 @@ void CalendarExample::on_font_button_font_set()
     (font_size == 0 ? "" : "    font-size: " + std::to_string(font_size / PANGO_SCALE) + "pt;\n") +
     "}";
 
-  try
-  {
-    css_provider_->load_from_data(css);
-  }
-  catch (const Gtk::CssProviderError& ex)
-  {
-    std::cerr << "CssProviderError, Gtk::CssProvider::load_from_data() failed: "
-              << ex.what() << std::endl;
-  }
-  catch (const Glib::Error& ex)
-  {
-    std::cerr << "Error, Gtk::CssProvider::load_from_data() failed: "
-              << ex.what() << std::endl;
-  }
+  css_provider_->load_from_data(css);
 }
 
 void CalendarExample::on_button_close()
@@ -160,10 +147,12 @@ void CalendarExample::on_parsing_error(const Glib::RefPtr<const Gtk::CssSection>
       std::cerr << "  URI = " << file->get_uri() << std::endl;
     }
 
-    std::cerr << "  start_line = " << section->get_start_line()+1
-              << ", end_line = " << section->get_end_line()+1 << std::endl;
-    std::cerr << "  start_position = " << section->get_start_position()
-              << ", end_position = " << section->get_end_position() << std::endl;
+    auto start_location = section->get_start_location();
+    auto end_location = section->get_end_location();
+    std::cerr << "  start_line = " << start_location.get_lines()+1
+              << ", end_line = " << end_location.get_lines()+1 << std::endl;
+    std::cerr << "  start_position = " << start_location.get_line_chars()
+              << ", end_position = " << end_location.get_line_chars() << std::endl;
   }
 }
 


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