diff --git a/include/wx/gtk/private/treeview.h b/include/wx/gtk/private/treeview.h new file mode 100644 index 0000000000..d029a8ff78 --- /dev/null +++ b/include/wx/gtk/private/treeview.h @@ -0,0 +1,62 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: wx/gtk/private/treeview.h +// Purpose: Private helpers for wxGTK controls using GtkTreeView +// Author: Vadim Zeitlin +// Created: 2016-02-06 (extracted from src/gtk/dataview.cpp) +// Copyright: (c) 2016 Vadim Zeitlin +// Licence: wxWindows licence +/////////////////////////////////////////////////////////////////////////////// + +#ifndef _GTK_PRIVATE_TREEVIEW_H_ +#define _GTK_PRIVATE_TREEVIEW_H_ + +// ---------------------------------------------------------------------------- +// wxGtkTreePath: RAII wrapper for GtkTreePath +// ---------------------------------------------------------------------------- + +// Usually this object is initialized with the associated GtkTreePath +// immediately when it's constructed but it can also be changed later either by +// using Assign() or by getting the pointer to the internally stored pointer +// value using ByRef(). The latter should be avoided but is very convenient +// when using GTK functions with GtkTreePath output parameters. +class wxGtkTreePath +{ +public: + // Ctor takes ownership of the given path and will free it if non-NULL. + wxGtkTreePath(GtkTreePath *path = NULL) : m_path(path) { } + + // Creates a tree path for the given string path. + wxGtkTreePath(const gchar *strpath) + : m_path(gtk_tree_path_new_from_string(strpath)) + { + } + + // Set the stored pointer if not done by ctor. + void Assign(GtkTreePath *path) + { + wxASSERT_MSG( !m_path, "shouldn't be already initialized" ); + + m_path = path; + } + + // Return the pointer to the internally stored pointer. This should only be + // used to initialize the object by passing it to some GTK function. + GtkTreePath **ByRef() + { + wxASSERT_MSG( !m_path, "shouldn't be already initialized" ); + + return &m_path; + } + + + operator GtkTreePath *() const { return m_path; } + + ~wxGtkTreePath() { if ( m_path ) gtk_tree_path_free(m_path); } + +private: + GtkTreePath *m_path; + + wxDECLARE_NO_COPY_CLASS(wxGtkTreePath); +}; + +#endif // _GTK_PRIVATE_TREEVIEW_H_ diff --git a/src/gtk/dataview.cpp b/src/gtk/dataview.cpp index 054a8e888f..3455a205b0 100644 --- a/src/gtk/dataview.cpp +++ b/src/gtk/dataview.cpp @@ -38,6 +38,7 @@ #include "wx/gtk/private/gdkconv.h" #include "wx/gtk/private/gtk2-compat.h" #include "wx/gtk/private/list.h" +#include "wx/gtk/private/treeview.h" using namespace wxGTKImpl; class wxGtkDataViewModelNotifier; @@ -59,55 +60,6 @@ extern "C" { typedef struct _GtkWxTreeModel GtkWxTreeModel; } -// ---------------------------------------------------------------------------- -// wxGtkTreePath: self-destroying GtkTreePath -// ---------------------------------------------------------------------------- - -// Usually this object is initialized with the associated GtkTreePath -// immediately when it's constructed but it can also be changed later either by -// using Assign() or by getting the pointer to the internally stored pointer -// value using ByRef(). The latter should be avoided but is very convenient -// when using GTK functions with GtkTreePath output parameters. -class wxGtkTreePath -{ -public: - // Ctor takes ownership of the given path and will free it if non-NULL. - wxGtkTreePath(GtkTreePath *path = NULL) : m_path(path) { } - - // Creates a tree path for the given string path. - wxGtkTreePath(const gchar *strpath) - : m_path(gtk_tree_path_new_from_string(strpath)) - { - } - - // Set the stored pointer if not done by ctor. - void Assign(GtkTreePath *path) - { - wxASSERT_MSG( !m_path, "shouldn't be already initialized" ); - - m_path = path; - } - - // Return the pointer to the internally stored pointer. This should only be - // used to initialize the object by passing it to some GTK function. - GtkTreePath **ByRef() - { - wxASSERT_MSG( !m_path, "shouldn't be already initialized" ); - - return &m_path; - } - - - operator GtkTreePath *() const { return m_path; } - - ~wxGtkTreePath() { if ( m_path ) gtk_tree_path_free(m_path); } - -private: - GtkTreePath *m_path; - - wxDECLARE_NO_COPY_CLASS(wxGtkTreePath); -}; - // ---------------------------------------------------------------------------- // wxGtkTreePathList: self-destroying list of GtkTreePath objects. // ----------------------------------------------------------------------------