[gtkmm] Gdk, Gtk: Update for the latest gtk4 and glib (no GTImeVal, etc.)



commit 5cc1c4ff7febf71fda3ad8ebb1a6873d81374252
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date:   Tue Aug 13 20:09:03 2019 +0200

    Gdk, Gtk: Update for the latest gtk4 and glib (no GTImeVal, etc.)
    
    * gdk/src/pixbufanimation.[ccg|hg]: create_from_file() takes a std::string
    instead of a Glib::ustring, and can throw an exception.
    get_iter() takes a gint64 instead of a Glib::TimeVal.
    * gdk/src/pixbufanimationiter.[ccg|hg]: advance() takes a gint64 instead
    of a Glib::TimeVal.
    * gtk/src/gesturelongpress.hg: Add set/get_delay_factor().
    * gtk/src/scale.hg: Remove signal_format_value().
    * gtk/src/treeviewcolumn.hg: Remove an argument from cell_get_size().
    * tools/m4/convert_gdk.m4: Add a conversion for GdkPixbufAnimation.

 gdk/src/pixbufanimation.ccg     | 17 +++++++++--------
 gdk/src/pixbufanimation.hg      | 42 +++++++++++++++++++++++++++++++++++++++--
 gdk/src/pixbufanimationiter.ccg | 11 +++++++++--
 gdk/src/pixbufanimationiter.hg  | 28 +++++++++++++++------------
 gtk/src/gesturelongpress.hg     |  3 +++
 gtk/src/scale.hg                | 13 +------------
 gtk/src/treeviewcolumn.hg       |  5 +----
 tools/m4/convert_gdk.m4         |  1 +
 8 files changed, 80 insertions(+), 40 deletions(-)
---
diff --git a/gdk/src/pixbufanimation.ccg b/gdk/src/pixbufanimation.ccg
index 55f7c4d9..158b1c4d 100644
--- a/gdk/src/pixbufanimation.ccg
+++ b/gdk/src/pixbufanimation.ccg
@@ -21,15 +21,16 @@
 namespace Gdk
 {
 
-Glib::RefPtr<PixbufAnimation> PixbufAnimation::create_from_file(const Glib::ustring& filename)
+G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+Glib::RefPtr<PixbufAnimationIter> PixbufAnimation::get_iter(gint64 start_time)
 {
-  GError* gerror = nullptr;
-  return Glib::wrap(gdk_pixbuf_animation_new_from_file(filename.c_str(), &gerror));
-
-  if(gerror)
-    ::Glib::Error::throw_exception(gerror);
+  // GTimeVal is deprecated, but gdk-pixbuf has no replacement for
+  // gdk_pixbuf_animation_get_iter() without GTimeVal.
+  GTimeVal tv;
+  tv.tv_sec = start_time / 1000000;
+  tv.tv_usec = start_time % 1000000;
+  return Glib::wrap(gdk_pixbuf_animation_get_iter(gobj(), &tv));
 }
+G_GNUC_END_IGNORE_DEPRECATIONS
 
 } //namespace Gdk
-
-
diff --git a/gdk/src/pixbufanimation.hg b/gdk/src/pixbufanimation.hg
index a62c1e02..7e503e8c 100644
--- a/gdk/src/pixbufanimation.hg
+++ b/gdk/src/pixbufanimation.hg
@@ -43,13 +43,51 @@ protected:
 
 public:
 
-  static Glib::RefPtr<PixbufAnimation> create_from_file(const Glib::ustring& filename);
+  _WRAP_METHOD(static Glib::RefPtr<PixbufAnimation> create_from_file(const std::string& filename),
+    gdk_pixbuf_animation_new_from_file, errthrow)
 
   _WRAP_METHOD(int get_width() const, gdk_pixbuf_animation_get_width)
   _WRAP_METHOD(int get_height() const, gdk_pixbuf_animation_get_height)
   _WRAP_METHOD(bool is_static_image() const, gdk_pixbuf_animation_is_static_image)
   _WRAP_METHOD(Glib::RefPtr<Pixbuf> get_static_image(), gdk_pixbuf_animation_get_static_image, refreturn)
-  _WRAP_METHOD(Glib::RefPtr<PixbufAnimationIter> get_iter(const GTimeVal* start_time), 
gdk_pixbuf_animation_get_iter)
+
+  /** Get an iterator for displaying an animation.
+   * The iterator provides the frames that should be displayed at a given time.
+   *
+   * @a start_time would normally come from g_get_real_time(), and marks
+   * the beginning of animation playback. After creating an iterator, you
+   * should immediately display the pixbuf returned by
+   * Gdk::PixbufAnimationIter::get_pixbuf(). Then, you should install
+   * a timeout (with Glib::signal_timeout().connect()) or by some other mechanism
+   * ensure that you'll update the image after
+   * Gdk::PixbufAnimationIter::get_delay_time() milliseconds. Each time
+   * the image is updated, you should reinstall the timeout with the new,
+   * possibly-changed delay time.
+   *
+   * As a shortcut, the default value of @a start_time is g_get_real_time().
+   *
+   * To update the image (i.e. possibly change the result of
+   * Gdk::PixbufAnimationIter::get_pixbuf() to a new frame of the animation),
+   * call Gdk::PixbufAnimationIter::advance().
+   *
+   * If you're using Gdk::PixbufLoader, in addition to updating the image
+   * after the delay time, you should also update it whenever you
+   * receive the area_updated signal and
+   * Gdk::PixbufAnimationIter::on_currently_loading_frame() returns
+   * <tt>true</tt>. In this case, the frame currently being fed into the loader
+   * has received new data, so needs to be refreshed. The delay time for
+   * a frame may also be modified after an area_updated signal, for
+   * example if the delay time for a frame is encoded in the data after
+   * the frame itself. So your timeout should be reinstalled after any
+   * area_updated signal.
+   *
+   * A delay time of -1 is possible, indicating "infinite."
+   *
+   * @param start_time Time when the animation starts playing.
+   * @return An iterator to move over the animation.
+   */
+  Glib::RefPtr<PixbufAnimationIter> get_iter(gint64 start_time = g_get_real_time());
+  _IGNORE(gdk_pixbuf_animation_get_iter)
 };
 
 } // namespace Gdk
diff --git a/gdk/src/pixbufanimationiter.ccg b/gdk/src/pixbufanimationiter.ccg
index 90559ea8..b857353c 100644
--- a/gdk/src/pixbufanimationiter.ccg
+++ b/gdk/src/pixbufanimationiter.ccg
@@ -19,10 +19,17 @@
 namespace Gdk
 {
 
-bool PixbufAnimationIter::advance()
+G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+bool PixbufAnimationIter::advance(gint64 current_time)
 {
-  return gdk_pixbuf_animation_iter_advance(gobj(), nullptr);
+  // GTimeVal is deprecated, but gdk-pixbuf has no replacement for
+  // gdk_pixbuf_animation_iter_advance() without GTimeVal.
+  GTimeVal tv;
+  tv.tv_sec = current_time / 1000000;
+  tv.tv_usec = current_time % 1000000;
+  return gdk_pixbuf_animation_iter_advance(gobj(), &tv);
 }
+G_GNUC_END_IGNORE_DEPRECATIONS
 
 } //namespace Gdk
 
diff --git a/gdk/src/pixbufanimationiter.hg b/gdk/src/pixbufanimationiter.hg
index 39b439da..ed1d7746 100644
--- a/gdk/src/pixbufanimationiter.hg
+++ b/gdk/src/pixbufanimationiter.hg
@@ -18,7 +18,6 @@
 
 #include <glibmm/object.h>
 #include <gdkmm/pixbuf.h>
-#include <glibmm/timeval.h>
 #include <gdk-pixbuf/gdk-pixbuf.h>
 
 _DEFS(gdkmm,gdk)
@@ -28,7 +27,6 @@ _PINCLUDE(glibmm/private/object_p.h)
 namespace Gdk
 {
 
-
 /** An iterator which points to a certain position in a PixbufAnimation.
  */
 class PixbufAnimationIter : public Glib::Object
@@ -46,23 +44,29 @@ public:
 
   _WRAP_METHOD(bool on_currently_loading_frame() const, gdk_pixbuf_animation_iter_on_currently_loading_frame)
 
-#m4 _CONVERSION(`const Glib::TimeVal&', `const GTimeVal*', static_cast<$2>(&$3))
-  _WRAP_METHOD(bool advance(const Glib::TimeVal& current_time), gdk_pixbuf_animation_iter_advance)
-
   /** Possibly advances an animation to a new frame. Chooses the frame based
    * on the start time passed to Gdk::PixbufAnimation::get_iter().
    *
-   * If this function returns false, there's no need to update the animation
+   * @a current_time would normally come from g_get_real_time(), and
+   * must be greater than or equal to the time passed to
+   * Gdk::PixbufAnimation::get_iter(), and must increase or remain
+   * unchanged each time get_pixbuf() is called.
+   * That is, you can't go backward in time; animations only play forward.
+   *
+   * As a shortcut, the default value of @a current_time is g_get_real_time().
+   * So you only need to explicitly pass @a current_time if you're doing
+   * something odd like playing the animation at double speed.
+   *
+   * If this function returns <tt>false</tt>, there's no need to update the animation
    * display, assuming the display had been rendered prior to advancing;
-   * if true, you need to call get_pixbuf() and update the
+   * if <tt>true</tt>, you need to call get_pixbuf() and update the
    * display with the new pixbuf.
    *
-   * @newin{2,14}
-   *
-   * @return true if the image may need updating.
+   * @param current_time Current time.
+   * @return <tt>true</tt> if the image may need updating.
    */
-  bool advance();
+  bool advance(gint64 current_time = g_get_real_time());
+  _IGNORE(gdk_pixbuf_animation_iter_advance)
 };
 
 } // namespace Gdk
-
diff --git a/gtk/src/gesturelongpress.hg b/gtk/src/gesturelongpress.hg
index 8dabd0b8..4a3c351c 100644
--- a/gtk/src/gesturelongpress.hg
+++ b/gtk/src/gesturelongpress.hg
@@ -52,6 +52,9 @@ public:
    */
   _WRAP_CREATE()
 
+  _WRAP_METHOD(void set_delay_factor(double delay_factor), gtk_gesture_long_press_set_delay_factor)
+  _WRAP_METHOD(double get_delay_factor() const, gtk_gesture_long_press_get_delay_factor)
+
   // no_default_handler because GtkGestureLongPressClass is private.
   _WRAP_SIGNAL(void pressed(double x, double y), "pressed", no_default_handler)
   _WRAP_SIGNAL(void cancelled(), "cancelled", no_default_handler)
diff --git a/gtk/src/scale.hg b/gtk/src/scale.hg
index 212298d4..06017521 100644
--- a/gtk/src/scale.hg
+++ b/gtk/src/scale.hg
@@ -75,7 +75,6 @@ public:
    */
   _WRAP_METHOD(bool get_draw_value() const, gtk_scale_get_draw_value)
 
-
   /** Set the position in which the value is displayed.
    */
   _WRAP_METHOD(void set_value_pos(PositionType pos), gtk_scale_set_value_pos)
@@ -84,7 +83,6 @@ public:
    */
   _WRAP_METHOD(PositionType get_value_pos() const, gtk_scale_get_value_pos)
 
-
   _WRAP_METHOD(void set_has_origin(bool has_origin = true), gtk_scale_set_has_origin)
   _WRAP_METHOD(bool get_has_origin() const, gtk_scale_get_has_origin)
 
@@ -95,16 +93,7 @@ public:
   _WRAP_METHOD(void add_mark(double value, PositionType position, const Glib::ustring& markup), 
gtk_scale_add_mark)
   _WRAP_METHOD(void clear_marks(), gtk_scale_clear_marks)
 
-#m4begin
-dnl// The ::format_value signal handler should return a newly allocated string.
-dnl// (which is obviously not a const gchar*)
-dnl// Also, ensure that format_value never returns an empty char[],
-dnl// because that could be caused by an intermediate empty ustring from an initial null char*.
-dnl// See bug http://bugzilla.gnome.org/show_bug.cgi?id=168747.
-  _CONVERSION(`Glib::ustring',`gchar*',`g_strdup(Glib::c_str_or_nullptr($3))')
-  _CONVERSION(`gchar*',`Glib::ustring',`Glib::convert_return_gchar_ptr_to_ustring($3)')
-#m4end
-  _WRAP_SIGNAL(Glib::ustring format_value(double value), "format_value")
+  //!!_WRAP_METHOD(void set_format_value_func(???), gtk_scale_set_format_value_func)
 
   _WRAP_PROPERTY("digits", int)
   _WRAP_PROPERTY("draw-value", bool)
diff --git a/gtk/src/treeviewcolumn.hg b/gtk/src/treeviewcolumn.hg
index cacd3478..9cc0e1bc 100644
--- a/gtk/src/treeviewcolumn.hg
+++ b/gtk/src/treeviewcolumn.hg
@@ -189,12 +189,9 @@ void set_renderer(Gtk::CellRenderer& renderer, const TreeModelColumnBase& column
   _WRAP_METHOD(void set_sort_order(SortType order), gtk_tree_view_column_set_sort_order)
   _WRAP_METHOD(SortType get_sort_order() const, gtk_tree_view_column_get_sort_order)
 
-
   _WRAP_METHOD(void cell_set_cell_data(const Glib::RefPtr<TreeModel>& tree_model, const TreeModel::iterator& 
iter, bool is_expander, bool is_expanded), gtk_tree_view_column_cell_set_cell_data)
 
-  //TODO: cell_area can be NULL. Add a method overload.
-  //But see http://bugzilla.gnome.org/show_bug.cgi?id=542329 about the lack of C documentation.
-  _WRAP_METHOD(void cell_get_size(const Gdk::Rectangle& cell_area, int& x_offset, int& y_offset, int& width, 
int& height) const, gtk_tree_view_column_cell_get_size)
+  _WRAP_METHOD(void cell_get_size(int& x_offset, int& y_offset, int& width, int& height) const, 
gtk_tree_view_column_cell_get_size)
 
   _WRAP_METHOD(bool cell_is_visible() const, gtk_tree_view_column_cell_is_visible)
   _WRAP_METHOD(void focus_cell(CellRenderer& cell), gtk_tree_view_column_focus_cell)
diff --git a/tools/m4/convert_gdk.m4 b/tools/m4/convert_gdk.m4
index b629d688..d3b6accd 100644
--- a/tools/m4/convert_gdk.m4
+++ b/tools/m4/convert_gdk.m4
@@ -200,6 +200,7 @@ _CONVERSION(`GdkPixbuf*',`Glib::RefPtr<Gdk::Pixbuf>', `Glib::wrap($3)')
 _CONVERSION(`GdkPixbuf*',`Glib::RefPtr<const Gdk::Pixbuf>', `Glib::wrap($3)')
 _CONVERSION(`GdkPixbufAnimationIter*',`Glib::RefPtr<PixbufAnimationIter>', `Glib::wrap($3)')
 _CONVERSION(`GdkPixbuf*',`Glib::RefPtr<Gdk::Pixbuf>', Glib::wrap($3))
+_CONVERSION(`GdkPixbufAnimation*',`Glib::RefPtr<PixbufAnimation>', `Glib::wrap($3)')
 _CONVERSION(`GdkPixbufAnimation*',`Glib::RefPtr<Gdk::PixbufAnimation>', `Glib::wrap($3)')
 _CONVERSION(`GdkPixbufAnimation*',`Glib::RefPtr<const Gdk::PixbufAnimation>', `Glib::wrap($3)')
 


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