[gtkmm] Gtk::Scale: Add [un]set_format_value_func()



commit 0e82d2b71d5f619f4a040449063e6d5f685d50da
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date:   Sat Aug 17 11:25:10 2019 +0200

    Gtk::Scale: Add [un]set_format_value_func()
    
    and change event(const Glib::RefPtr<const Gdk::Event>&) to
    event(const Glib::RefPtr<Gdk::Event>&) (non-const Event).
    gtk_widget_event() was changed correspondingly.

 gtk/src/gtk_docs.xml     |  6 +++++-
 gtk/src/gtk_methods.defs |  3 ++-
 gtk/src/scale.ccg        | 38 ++++++++++++++++++++++++++++++++++++++
 gtk/src/scale.hg         | 33 ++++++++++++++++++++++++++++++++-
 gtk/src/widget.hg        |  2 +-
 5 files changed, 78 insertions(+), 4 deletions(-)
---
diff --git a/gtk/src/gtk_docs.xml b/gtk/src/gtk_docs.xml
index 1c0930e9..cd06756a 100644
--- a/gtk/src/gtk_docs.xml
+++ b/gtk/src/gtk_docs.xml
@@ -61860,6 +61860,10 @@ its own, rounded according to the value of the #GtkScale:digits property.
 <parameter_description> user data to pass to @func
 </parameter_description>
 </parameter>
+<parameter name="destroy_notify">
+<parameter_description> destroy function for @user_data
+</parameter_description>
+</parameter>
 </parameters>
 <return></return>
 </function>
@@ -73841,7 +73845,7 @@ take over an existing reference.
 <function name="gtk_text_view_place_cursor_onscreen">
 <description>
 Moves the cursor to the currently visible region of the
-buffer, it it isn’t there already.
+buffer, if it isn’t there already.
 
 
 </description>
diff --git a/gtk/src/gtk_methods.defs b/gtk/src/gtk_methods.defs
index 98596fd2..041a01ce 100644
--- a/gtk/src/gtk_methods.defs
+++ b/gtk/src/gtk_methods.defs
@@ -20884,6 +20884,7 @@
   (parameters
     '("GtkScaleFormatValueFunc" "func")
     '("gpointer" "user_data")
+    '("GDestroyNotify" "destroy_notify")
   )
 )
 
@@ -29615,7 +29616,7 @@
   (c-name "gtk_widget_event")
   (return-type "gboolean")
   (parameters
-    '("const-GdkEvent*" "event")
+    '("GdkEvent*" "event")
   )
 )
 
diff --git a/gtk/src/scale.ccg b/gtk/src/scale.ccg
index bbeb6653..6426af2e 100644
--- a/gtk/src/scale.ccg
+++ b/gtk/src/scale.ccg
@@ -25,6 +25,27 @@
 
 using std::strlen;
 
+namespace
+{
+
+char* SignalProxy_Scale_format_value_callback(GtkScale* /* scale */,
+  double value, gpointer user_data)
+{
+  auto the_slot = static_cast<Gtk::Scale::SlotFormatValue*>(user_data);
+
+  try
+  {
+    return g_strdup(((*the_slot)(value)).c_str());
+  }
+  catch (...)
+  {
+    Glib::exception_handlers_invoke();
+  }
+  return g_strdup("?");
+}
+
+} // anonymous namespace
+
 namespace Gtk
 {
 
@@ -40,4 +61,21 @@ Scale::Scale(const Glib::RefPtr<Adjustment>& adjustment, Orientation orientation
 {
 }
 
+void Scale::set_format_value_func(const SlotFormatValue& slot)
+{
+  // Create a copy of the slot object. A pointer to this will be passed
+  // through the callback's data parameter. It will be deleted
+  // when Glib::destroy_notify_delete<SlotFormatValue> is called.
+  auto slot_copy = new SlotFormatValue(slot);
+
+  gtk_scale_set_format_value_func(gobj(),
+    &SignalProxy_Scale_format_value_callback, slot_copy,
+    &Glib::destroy_notify_delete<SlotFormatValue>);
+}
+
+void Scale::unset_format_value_func()
+{
+  gtk_scale_set_format_value_func(gobj(), nullptr, nullptr, nullptr);
+}
+
 } // namespace Gtk
diff --git a/gtk/src/scale.hg b/gtk/src/scale.hg
index 06017521..52067e5d 100644
--- a/gtk/src/scale.hg
+++ b/gtk/src/scale.hg
@@ -93,7 +93,38 @@ 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)
 
-  //!!_WRAP_METHOD(void set_format_value_func(???), gtk_scale_set_format_value_func)
+  /** Slot that formats the value.
+   *
+   * For instance:
+   * @code
+   * Glib::ustring on_format_value(double value);
+   * @endcode
+   *
+   * If set_format_value() is not used, the value will be displayed on
+   * its own, rounded according to the value of property_digits().
+   *
+   * @param value The numeric value to format.
+   * @return A string describing a textual representation of the given numerical value.
+   */
+  using SlotFormatValue = sigc::slot<Glib::ustring(double)>;
+
+  /** Changes how the scale value is displayed.
+   *
+   * The given slot will return a string representing the value.
+   * That string will then be used to display the scale's value.
+   *
+   * If this method is not called, or if unset_format_value_func() is called
+   * afterwards, the value will be displayed on its own, rounded according
+   * to the value of property_digits().
+   *
+   * @param slot Slot that formats the value.
+   */
+  void set_format_value_func(const SlotFormatValue& slot);
+  _IGNORE(gtk_scale_set_format_value_func)
+
+  /** Undoes the effect of a previous call to set_format_value_func().
+   */
+  void unset_format_value_func();
 
   _WRAP_PROPERTY("digits", int)
   _WRAP_PROPERTY("draw-value", bool)
diff --git a/gtk/src/widget.hg b/gtk/src/widget.hg
index e8a5f667..d10a3998 100644
--- a/gtk/src/widget.hg
+++ b/gtk/src/widget.hg
@@ -173,7 +173,7 @@ public:
   _IGNORE(gtk_widget_can_activate_accel)
   //Probably not useful. Too C-specific: _WRAP_METHOD(bool can_activate_accel(guint signal_id) const, 
gtk_widget_can_activate_accel)
 
-  _WRAP_METHOD(bool event(const Glib::RefPtr<const Gdk::Event>& gdk_event), gtk_widget_event)
+  _WRAP_METHOD(bool event(const Glib::RefPtr<Gdk::Event>& gdk_event), gtk_widget_event)
   _WRAP_METHOD(bool activate(), gtk_widget_activate)
 
   // gtk_widget_reparent() has been removed, but we want to keep Gtk::Widget::reparent().


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