Re: [gtkmm] Custom TreeStore Problems
- From: Christof Petig <christof petig-baender de>
- To: Murray Cumming Comneon com
- Cc: gtkmm-list gnome org
- Subject: Re: [gtkmm] Custom TreeStore Problems
- Date: Thu, 09 Oct 2003 17:37:19 +0200
Murray Cumming Comneon com schrieb:
Ok, I figured out that I need something like
Glib::Object(Glib::ConstructParams(treestore_class_.init(),
(char*) 0))
I find that surprising.
In this case I send you a copy of the failing program.
Christof
// $Id: Event.cc,v 1.2 2003/05/12 06:37:03 christof Exp $
/* ManuProcWidgets: ManuProC's GUI element library
* Copyright (C) 2001 Adolf Petig GmbH & Co. KG, written by Christof Petig
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
//#include <gtkmm/treemodel.h>
#include <gtkmm/window.h>
#include <gtkmm/treeview.h>
#include <gtkmm/main.h>
//#include <gobject/gtype.h>
#include <cassert>
#include <vector>
#include <cstdio>
static const unsigned columns=4;
static const unsigned rows=10;
static std::string itoa(int i)
{ char buf[20];
snprintf(buf,sizeof buf,"%d",i);
buf[sizeof(buf)-1]=0;
return buf;
}
static unsigned iter2row(const GtkTreeIter* iter)
{ return reinterpret_cast<unsigned>(iter->user_data);
}
static unsigned &iter2row(GtkTreeIter* iter)
{ return reinterpret_cast<unsigned&>(iter->user_data);
}
#if 0
class MyTreeModel_Class : public Glib::Class
{public:
const Glib::Class& init();
static void class_init_function(void* g_class, void* class_data);
static Glib::ObjectBase* wrap_new(GObject*);
};
#endif
class MyTreeModel : public Gtk::TreeModel
{ std::string data[rows][columns];
// static MyTreeModel_Class treestore_class_;
virtual Gtk::TreeModelFlags get_flags_vfunc()
{ return Gtk::TreeModelFlags(0); }
virtual int get_n_columns_vfunc()
{ return columns; }
virtual GType get_column_type_vfunc(int index)
{ return G_TYPE_STRING; }
virtual void get_value_vfunc(const TreeModel::iterator& iter, int column,
GValue* value)
{ g_value_set_static_string(value,data[iter2row(iter.gobj())][column].c_str());
}
virtual bool iter_next_vfunc(GtkTreeIter* iter)
{ iter2row(iter)++;
return iter2row(iter)<rows;
}
virtual bool iter_children_vfunc(GtkTreeIter* iter, const GtkTreeIter* parent)
{ return false;
}
virtual bool iter_has_child_vfunc(const GtkTreeIter* iter)
{ return false;
}
virtual int iter_n_children_vfunc(const GtkTreeIter* iter)
{ return 0;
}
virtual bool iter_nth_child_vfunc(GtkTreeIter* iter, const GtkTreeIter* parent, int n)
{ return false;
}
virtual bool iter_parent_vfunc(GtkTreeIter* iter, const GtkTreeIter* child)
{ return false;
}
virtual Gtk::TreeModel::Path get_path_vfunc(const Gtk::TreeModel::iterator& iter)
{ return Gtk::TreeModel::Path();
}
virtual bool get_iter_vfunc(GtkTreeIter* iter, const Gtk::TreeModel::Path& path)
{ return false;
}
public:
MyTreeModel()
: Glib::ObjectBase(typeid(MyTreeModel))
// , Glib::Object(Glib::ConstructParams(treestore_class_.init(), (char*) 0))
// Gtk::TreeModel()
{ for (unsigned r=0;r<rows;++r)
for (unsigned c=0;c<columns;++c)
{ data[r][c]=itoa(r+c);
}
}
};
int main(int argc,char **argv)
{ Gtk::Main m(argc,argv);
Gtk::Window w;
Gtk::TreeView v;
MyTreeModel model;
std::vector<Gtk::TreeModelColumn< int > > cols(columns);
Gtk::TreeModel::ColumnRecord colrec;
for (unsigned i=0;i<columns;++i) colrec.add(cols[i]);
w.add(v);
v.set_model(Glib::RefPtr<Gtk::TreeModel>(&model));
for (unsigned i=0;i<columns;++i)
{ //CellRendererText *r=manage(new CellRendererText);
// Gtk::TreeViewColumn *col
// =manage(new Gtk::TreeViewColumn("column",*render));
v.append_column("data",cols[i]);
// col->add_attribute (render->property_text (),
}
v.show();
w.show();
m.run(w);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]