[gtkmm] Understanding Gtk::TreeView



Hello, I was wondering if someone could verify my understanding of the Gtk::TreeView (and related) classes. I come from Windows programming background and implementing the Gtk::TreeView seems to be overly-complex.


Hopefully, you will be able to understand my pseudocode, I've placed comments throughout which tell what I think is going on.




#include <all_the_necessary_headers...blah..blah.h>

/*
	This class represents a vertical column of data
	each branch of the tree can have data (i.e. string) 
	in each column. this class tracks all of those columns.
	Is this a linked list???
*/

class MyTreeViewColumns : public Gtk::TreeModel::ColumnRecord
{
public:
	MyTreeViewCoumns() { add(m_col_text); }	// when we create a new 
	Gtk::TreeModelColumn<Glib::ustring>	m_col_text;	// this is the "name" of the column??
};


/*
	This class represents the TreeView as a whole
*/

class MyTreeView : public Gtk::ScrolledWindow
{
public:
	MyTreeView();
	~MyTreeView();

	MyTreeViewColumns	m_Columns;

protected:
	Glib::RefPtr<Gtk::ListStore>	m_refListStore;
	Gtk::TreeView			m_TreeView

	// m_refListStore is a smart-pointer to a linked list of items
	// 	that are 'in' the tree. One thing i'm not sure of is 
	// 	how the list is sorted. what about items that have 
	//	children that have children?
	//
	// m_TreeView is the class that handles the display of the TreeView,
	// 	emits signals for events (expanded, collapsed) for the treeview.
};



// IMPLEMENTATION:
MyTreeView::MyTreeView()
{
	set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); // expand the tree as needed

	add(m_TreeView);	// the tree view is to be part of this Gtk::ScrolledWindow

	m_refListStore = Gtk::ListStore::create(m_Columns);	// create the list store,
								// the list store is where we store all of the 'stuff'
								// to be displayed? for each column?

	m_TreeView.set_model(m_refListStore);			// tell the treeview to use the data in the m_refListStore

	// add some test branches to the tree
	for(int i = 0; i < 10; ++i)
	{
		Gtk::TreeModel::Row row = *(m_refListStore->append());	// create a new item (branch? leaf?) in the tree
		const Glib::ScopedPtr<char> text_buf(g_strdup_printf("message #%d", i)); // const Glib::ScopedPtr<char> looks like a fancy c-style string, is it?
		row[m_Columns.m_col_text] = text_buf.get();	// I'm confused here by row[m_Columns.m_col_text].... are we using as an index of the array of available columns?
	}

	m_TreeView.append_column("Messages", m_Columns.m_col_text); // i'm pretty sure this just adds the column to the treeview (hasta have at least 1 column, right?) 
								   // but i need to look at the documentation for append_column before i know what's going on.


	show_all_children();	// tell Gtk to show our widgets
}

MyTreeView::~MyTreeView()
{
}



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