[gtkmm/gtkmm-2-24] Update to be more compatible with glibmm 2.47.6 and later
- From: Kjell Ahlstedt <kjellahl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtkmm/gtkmm-2-24] Update to be more compatible with glibmm 2.47.6 and later
- Date: Wed, 25 May 2016 16:40:24 +0000 (UTC)
commit db08358e3a89a5b97daf4b5126b3e97b42e99022
Author: Kjell Ahlstedt <kjell ahlstedt bredband net>
Date: Wed May 25 18:26:37 2016 +0200
Update to be more compatible with glibmm 2.47.6 and later
* gdk/src/types.hg: Glib::ScopedPtr has been deprecated. To be able to build
gtkmm with GLIBMM_DISABLE_DEPRECATED, copy Glib::ScopedPtr to Gdk::ScopedPtr.
* gdk/src/types.ccg:
* gtk/src/clipboard.ccg:
* gtk/src/colorselection.ccg:
* gtk/src/rc.ccg:
* gtk/src/widget.ccg:
* demos/gtk-demo/example_dialog.cc: Use Gdk::ScopedPtr instead of
Glib::ScopedPtr.
* gtk/src/menushell.ccg: Glib::Refptr::operator bool() has been made explicit.
It's no longer used in item != 0, where item is a RefPtr. Change the
expression to the equivalent !!item.
Even with these changes it's not unproblematic to build gtkmm2 with a new
version of gmmproc, because _CLASS_BOXEDTYPE and _CLASS_GOBJECT generate
move operators but gtkmm2 does not require a C++11 compiler.
demos/gtk-demo/example_dialog.cc | 2 +-
gdk/src/types.ccg | 2 +-
gdk/src/types.hg | 24 ++++++++++++++++++++++++
gtk/src/clipboard.ccg | 3 +--
gtk/src/colorselection.ccg | 2 +-
gtk/src/menushell.ccg | 2 +-
gtk/src/rc.ccg | 5 ++---
gtk/src/widget.ccg | 8 ++++----
8 files changed, 35 insertions(+), 13 deletions(-)
---
diff --git a/demos/gtk-demo/example_dialog.cc b/demos/gtk-demo/example_dialog.cc
index e41aada..b86e1c1 100644
--- a/demos/gtk-demo/example_dialog.cc
+++ b/demos/gtk-demo/example_dialog.cc
@@ -113,7 +113,7 @@ void Example_Dialog::on_button_message()
Glib::ustring strMessage = "This message box has been popped up the following\n"
"number of times:\n\n";
{
- Glib::ScopedPtr<char> buf (g_strdup_printf("%d", m_count));
+ Gdk::ScopedPtr<char> buf (g_strdup_printf("%d", m_count));
strMessage += buf.get();
}
Gtk::MessageDialog dialog(strMessage, false, Gtk::MESSAGE_INFO, Gtk::BUTTONS_OK, true); //true = modal
diff --git a/gdk/src/types.ccg b/gdk/src/types.ccg
index a5a28e4..6538d85 100644
--- a/gdk/src/types.ccg
+++ b/gdk/src/types.ccg
@@ -48,7 +48,7 @@ GdkAtom AtomStringTraits::to_c_type(const std::string& atom_name)
std::string AtomStringTraits::to_cpp_type(GdkAtom atom)
{
if(char *const atom_name = gdk_atom_name(atom))
- return std::string(Glib::ScopedPtr<char>(atom_name).get());
+ return std::string(Gdk::ScopedPtr<char>(atom_name).get());
else
return std::string();
}
diff --git a/gdk/src/types.hg b/gdk/src/types.hg
index a05ba0c..bb75c68 100644
--- a/gdk/src/types.hg
+++ b/gdk/src/types.hg
@@ -127,6 +127,30 @@ struct AtomStringTraits
// we don't want it to look like we're calling a template trait, but
// a utility function. -Bryan
typedef AtomStringTraits AtomString;
+
+// Glib::ScopedPtr has been deprecated in glibmm 2.47.6.
+// We don't want to use the replacement, Glib::make_unique_ptr_gfree(),
+// in gtkmm-2, because it requires C++11. Instead, add this identical Gdk::ScopedPtr,
+// intended only for internal use in gtkmm.
+
+/** Helper to deal with memory allocated
+ * by GLib functions in an exception-safe manner.
+ */
+template <typename T>
+class ScopedPtr
+{
+private:
+ T* ptr_;
+ ScopedPtr(const ScopedPtr<T>&);
+ ScopedPtr<T>& operator=(const ScopedPtr<T>&);
+
+public:
+ ScopedPtr() : ptr_(nullptr) {}
+ explicit ScopedPtr(T* ptr) : ptr_(ptr) {}
+ ~ScopedPtr() noexcept { g_free(ptr_); }
+ T* get() const { return ptr_; }
+ T** addr() { return &ptr_; }
+};
#endif //DOXYGEN_SHOULD_SKIP_THIS
typedef Glib::ArrayHandle<std::string,AtomStringTraits> ArrayHandle_AtomString;
diff --git a/gtk/src/clipboard.ccg b/gtk/src/clipboard.ccg
index 0379162..6b74cf9 100644
--- a/gtk/src/clipboard.ccg
+++ b/gtk/src/clipboard.ccg
@@ -19,7 +19,6 @@
#include <gtkmm/textbuffer.h>
#include <gtkmm/selectiondata_private.h>
-#include <glibmm/utility.h> //For ScopedPtr<>.
#include <gtk/gtk.h>
namespace
@@ -320,7 +319,7 @@ std::string Clipboard::wait_for_rich_text(const Glib::RefPtr<TextBuffer>& buffer
{
gchar* format_atom_name = gdk_atom_name(format_atom);
if(format_atom_name)
- format = Glib::ScopedPtr<char>(format_atom_name).get(); //This frees the buffer.
+ format = Gdk::ScopedPtr<char>(format_atom_name).get(); //This frees the buffer.
result = std::string((char*)text, length);
g_free(text);
diff --git a/gtk/src/colorselection.ccg b/gtk/src/colorselection.ccg
index e665200..a91b647 100644
--- a/gtk/src/colorselection.ccg
+++ b/gtk/src/colorselection.ccg
@@ -86,7 +86,7 @@ Gdk::ArrayHandle_Color ColorSelection::palette_from_string(const Glib::ustring&
Glib::ustring ColorSelection::palette_to_string(const Gdk::ArrayHandle_Color& colors)
{
if(char *const str = gtk_color_selection_palette_to_string(colors.data(), colors.size()))
- return Glib::ustring(Glib::ScopedPtr<char>(str).get());
+ return Glib::ustring(Gdk::ScopedPtr<char>(str).get());
else
return Glib::ustring();
}
diff --git a/gtk/src/menushell.ccg b/gtk/src/menushell.ccg
index 6ca9db1..be22f0e 100644
--- a/gtk/src/menushell.ccg
+++ b/gtk/src/menushell.ccg
@@ -118,7 +118,7 @@ MenuList::iterator MenuList::insert(MenuList::iterator position, const Element&
{
const Glib::RefPtr<Gtk::MenuItem> item = element.get_child();
- g_return_val_if_fail(item != 0, position);
+ g_return_val_if_fail(!!item, position);
g_return_val_if_fail(gparent() != 0, position);
int pos = -1;
diff --git a/gtk/src/rc.ccg b/gtk/src/rc.ccg
index 3fa1215..6211744 100644
--- a/gtk/src/rc.ccg
+++ b/gtk/src/rc.ccg
@@ -18,7 +18,6 @@
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-#include <glibmm/utility.h>
#include <gtkmm/settings.h>
#include <gtkmm/widget.h>
#include <gtkmm/style.h>
@@ -30,13 +29,13 @@ namespace Gtk
void RcStyle::set_name(const Glib::ustring& name)
{
- const Glib::ScopedPtr<char> old_name (gobj()->name);
+ const Gdk::ScopedPtr<char> old_name (gobj()->name);
gobj()->name = g_strdup(name.c_str());
}
void RcStyle::set_bg_pixmap_name(StateType state, const Glib::ustring& name)
{
- const Glib::ScopedPtr<char> old_name (gobj()->bg_pixmap_name[state]);
+ const Gdk::ScopedPtr<char> old_name (gobj()->bg_pixmap_name[state]);
gobj()->bg_pixmap_name[state] = g_strdup(name.c_str());
}
diff --git a/gtk/src/widget.ccg b/gtk/src/widget.ccg
index be3c14d..4c1beb1 100644
--- a/gtk/src/widget.ccg
+++ b/gtk/src/widget.ccg
@@ -202,8 +202,8 @@ Widget* Widget::get_current_modal_grab()
void Widget::path(Glib::ustring& path_arg, Glib::ustring& path_reversed)
{
guint path_length = 0;
- Glib::ScopedPtr<gchar> path_ptr;
- Glib::ScopedPtr<gchar> rpath_ptr;
+ Gdk::ScopedPtr<gchar> path_ptr;
+ Gdk::ScopedPtr<gchar> rpath_ptr;
gtk_widget_path(gobj(), &path_length, path_ptr.addr(), rpath_ptr.addr());
@@ -214,8 +214,8 @@ void Widget::path(Glib::ustring& path_arg, Glib::ustring& path_reversed)
void Widget::class_path(Glib::ustring& path_arg, Glib::ustring& path_reversed)
{
guint path_length = 0;
- Glib::ScopedPtr<gchar> path_ptr;
- Glib::ScopedPtr<gchar> rpath_ptr;
+ Gdk::ScopedPtr<gchar> path_ptr;
+ Gdk::ScopedPtr<gchar> rpath_ptr;
gtk_widget_class_path(gobj(), &path_length, path_ptr.addr(), rpath_ptr.addr());
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]