[gtkmm] TextBuffer: get_selection_bounds(): Avoid warning about infinite recursion.



commit 10da66dea66af0643aaffd1de1e0df3697109511
Author: Murray Cumming <murrayc murrayc com>
Date:   Mon May 29 09:48:48 2017 +0200

    TextBuffer: get_selection_bounds(): Avoid warning about infinite recursion.
    
    clang++ complains about this, but I don't see how the const method
    could call itself on a non-const instance. Anyway, removing the
    constversion option is no great loss.

 gtk/src/textbuffer.hg     |    2 +-
 gtk/src/treeselection.ccg |   11 ++++++++++-
 2 files changed, 11 insertions(+), 2 deletions(-)
---
diff --git a/gtk/src/textbuffer.hg b/gtk/src/textbuffer.hg
index c2e3b06..df8ab93 100644
--- a/gtk/src/textbuffer.hg
+++ b/gtk/src/textbuffer.hg
@@ -490,7 +490,7 @@ public:
   _IGNORE(gtk_text_buffer_paste_clipboard)
 
   _WRAP_METHOD(bool get_selection_bounds(iterator& range_start, iterator& range_end), 
gtk_text_buffer_get_selection_bounds)
-  _WRAP_METHOD(bool get_selection_bounds(const_iterator& range_start, const_iterator& range_end) const, 
gtk_text_buffer_get_selection_bounds, constversion)
+  _WRAP_METHOD(bool get_selection_bounds(const_iterator& range_start, const_iterator& range_end) const, 
gtk_text_buffer_get_selection_bounds)
   _WRAP_METHOD(bool erase_selection(bool interactive = true, bool default_editable = true), 
gtk_text_buffer_delete_selection)
 
   _WRAP_METHOD(void select_range(const iterator& ins, const iterator& bound), gtk_text_buffer_select_range)
diff --git a/gtk/src/treeselection.ccg b/gtk/src/treeselection.ccg
index fdbf4f2..967f6a3 100644
--- a/gtk/src/treeselection.ccg
+++ b/gtk/src/treeselection.ccg
@@ -157,7 +157,16 @@ TreeModel::iterator TreeSelection::get_selected(Glib::RefPtr<TreeModel>& model)
 
 TreeModel::const_iterator TreeSelection::get_selected(Glib::RefPtr<const TreeModel>& model) const
 {
-  return const_cast<TreeSelection*>(this)->get_selected(model);
+  TreeModel::iterator iter;
+  GtkTreeModel* model_gobject = nullptr;
+
+  // If no row is selected, *iter.gobj() is set to an invalid iterator.
+  gtk_tree_selection_get_selected(const_cast<GtkTreeSelection*>(gobj()), &model_gobject, iter.gobj());
+
+  model = Glib::wrap(model_gobject, true);
+
+  iter.set_model_refptr(std::const_pointer_cast<TreeModel>(model));
+  return iter;
 }
 
 void TreeSelection::selected_foreach_iter(const SlotForeachIter& slot) const


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