File: treeview.h

package info (click to toggle)
wxpython4.0 4.2.3%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 221,752 kB
  • sloc: cpp: 962,555; python: 230,573; ansic: 170,731; makefile: 51,756; sh: 9,342; perl: 1,564; javascript: 584; php: 326; xml: 200
file content (62 lines) | stat: -rw-r--r-- 2,158 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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 <vadim@wxwidgets.org>
// 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_