Reference Manual
Inti Logo
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

treemodel.h

Go to the documentation of this file.
00001 /*  Inti: Integrated Foundation Classes
00002  *  Copyright (C) 2002-2003 The Inti Development Team.
00003  *  Copyright (C) 2000 Red Hat, Inc.
00004  *
00005  *  This program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2 of the License, or
00008  *  (at your option) any later version.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU Library General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU Library General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00018  */
00019  
00026 
00027 #ifndef INTI_GTK_TREE_MODEL_H
00028 #define INTI_GTK_TREE_MODEL_H
00029 
00030 #ifndef INTI_G_BOXED_H
00031 #include <inti/glib/boxed.h>
00032 #endif
00033 
00034 #ifndef INTI_G_TYPE_H
00035 #include <inti/glib/type.h>
00036 #endif
00037 
00038 #ifndef INTI_G_VALUE_H
00039 #include <inti/glib/value.h>
00040 #endif
00041 
00042 #ifndef __GTK_TREE_MODEL_H__
00043 #include <gtk/gtktreemodel.h>
00044 #endif
00045 
00046 #ifndef _CPP_VECTOR
00047 #include <vector>
00048 #endif
00049 
00050 namespace Inti {
00051 
00052 namespace G {
00053 class Object;
00054 class Value;
00055 }
00056 
00057 namespace Gtk {
00058         
00059 class SelectionData;
00060 class TreeModelIface;
00061 
00067 
00068 enum TreeModelFlags
00069 {
00070         TREE_MODEL_ITERS_PERSIST = GTK_TREE_MODEL_ITERS_PERSIST,
00072         
00073         TREE_MODEL_LIST_ONLY = GTK_TREE_MODEL_LIST_ONLY
00075 };
00076 
00078 
00079 typedef unsigned int TreeModelFlagsField;
00080 
00090 
00091 class TreePath : public G::Boxed
00092 {
00093 public:
00096 
00097         TreePath();
00099 
00100         explicit TreePath(const char *path);
00108 
00109         explicit TreePath(int first_index, ...);
00113         
00114         explicit TreePath(GtkTreePath *path);
00122 
00123         TreePath(GtkTreePath *path, bool copy);
00133 
00134         TreePath(const TreePath& src);
00137 
00138         ~TreePath();
00140 
00141         TreePath& operator=(const TreePath& src);
00144 
00148 
00149         GtkTreePath* gtk_tree_path() const { return (GtkTreePath*)boxed_; }
00151         
00152         operator GtkTreePath* () const;
00154         
00155         String to_string() const;
00159         
00160         int get_depth() const;
00162 
00163         std::vector<int> get_indices() const;
00166         
00167         int compare(const TreePath& other) const;
00175 
00176         bool is_ancestor(const TreePath& descendant) const;
00180                 
00181         bool is_descendant(const TreePath& ancestor) const;
00185                 
00186         bool operator==(const TreePath& other) const;
00188         
00189         bool operator!=(const TreePath& other) const;
00191         
00192         bool operator<(const TreePath& other) const;
00194         
00195         bool operator>(const TreePath& other) const;
00197         
00201 
00202         void append_index(int index);
00205                 
00206         void prepend_index(int index);
00209                 
00210         void next();
00212                 
00213         bool prev();
00216                 
00217         bool up();
00220                 
00221         void down();
00223         
00225 };
00226 
00237 
00238 class TreeIter : public G::Boxed
00239 {
00240 public:
00243 
00244         TreeIter();
00246 
00247         explicit TreeIter(GtkTreeIter *iter);
00255 
00256         TreeIter(GtkTreeIter *iter, bool copy);
00266 
00267         TreeIter(const TreeIter& src);
00270 
00271         ~TreeIter();
00273 
00274         TreeIter& operator=(const TreeIter& src);
00277         
00281 
00282         GtkTreeIter* gtk_tree_iter() const { return (GtkTreeIter*)boxed_; }
00284 
00285         operator GtkTreeIter* () const;
00287 
00289 };
00290 
00398 
00399 class TreeModel : public virtual G::TypeInterface
00400 {
00401         friend class TreeModelIface;
00402 
00403 protected:
00406 
00407         virtual ~TreeModel() = 0;
00409         
00411 //  Override these do_ methods when you want to change the default behaviour of the GtkTreeModel.
00412         
00413         virtual GtkTreeModelFlags do_get_flags();
00414 
00415         virtual gint do_get_n_columns();
00416 
00417         virtual GType do_get_column_type(int index);
00418 
00419         virtual gboolean do_get_iter(GtkTreeIter *iter, GtkTreePath *path);
00420 
00421         virtual GtkTreePath* do_get_path(GtkTreeIter *iter);
00422 
00423         virtual void do_get_value(GtkTreeIter *iter, int column, GValue *value);
00424 
00425         virtual gboolean do_iter_next(GtkTreeIter *iter);
00426 
00427         virtual gboolean do_iter_children(GtkTreeIter *iter, GtkTreeIter *parent);
00428 
00429         virtual gboolean do_iter_has_child(GtkTreeIter *iter);
00430 
00431         virtual gint do_iter_n_children(GtkTreeIter *iter);
00432 
00433         virtual gboolean do_iter_nth_child(GtkTreeIter *iter, GtkTreeIter *parent, int n);
00434 
00435         virtual gboolean do_iter_parent(GtkTreeIter *iter, GtkTreeIter *child);
00436 
00437         virtual void do_ref_node(GtkTreeIter *iter);
00438 
00439         virtual void do_unref_node(GtkTreeIter *iter);
00440 
00443 
00444         virtual void on_row_changed(const TreePath& path, const TreeIter& iter);
00448         
00449         virtual void on_row_inserted(const TreePath& path, const TreeIter& iter);
00453 
00454         virtual void on_row_has_child_toggled(const TreePath& path, const TreeIter& iter);
00458          
00459         virtual void on_row_deleted(const TreePath& path);
00462 
00463         virtual void on_rows_reordered(const TreePath& path, const TreeIter& iter, int *new_order);
00469 
00471 //  Signals
00472 
00473         typedef G::Signal2<void, GtkTreePath*, GtkTreeIter*> RowChangedSignalType;
00474         typedef G::SignalProxy<TypeInstance, RowChangedSignalType> RowChangedSignalProxy;
00475         static const RowChangedSignalType row_changed_signal;
00476 
00477         typedef G::Signal2<void, GtkTreePath*, GtkTreeIter*> RowInsertedSignalType;
00478         typedef G::SignalProxy<TypeInstance, RowInsertedSignalType> RowInsertedSignalProxy;
00479         static const RowInsertedSignalType row_inserted_signal;
00480 
00481         typedef G::Signal2<void, GtkTreePath*, GtkTreeIter*> RowHasChildToggledSignalType;
00482         typedef G::SignalProxy<TypeInstance, RowHasChildToggledSignalType> RowHasChildToggledSignalProxy;
00483         static const RowHasChildToggledSignalType row_has_child_toggled_signal;
00484 
00485         typedef G::Signal1<void, GtkTreePath*> RowDeletedSignalType;
00486         typedef G::SignalProxy<TypeInstance, RowDeletedSignalType> RowDeletedSignalProxy;
00487         static const RowDeletedSignalType row_deleted_signal;
00488 
00489         typedef G::Signal3<void, GtkTreePath*, GtkTreeIter*, int*> RowsReorderedSignalType;
00490         typedef G::SignalProxy<TypeInstance, RowsReorderedSignalType> RowsReorderedSignalProxy;
00491         static const RowsReorderedSignalType rows_reordered_signal;
00492 
00493 public:
00494 
00495         typedef Slot2<bool, const TreePath&, const TreeIter&> ForeachSlot;
00507 
00510 
00511         GtkTreeModel* gtk_tree_model() const { return (GtkTreeModel*)instance; }
00513 
00514         GtkTreeModelIface* gtk_tree_model_iface() const;
00516 
00517         operator GtkTreeModel* () const;
00519 
00520         TreeModelFlagsField get_flags() const;
00526 
00527         int get_n_columns() const;
00529 
00530         GType get_column_type(int index) const;
00534 
00535         bool get_iter(TreeIter& iter, const TreePath& path) const;
00540 
00541         bool get_iter(TreeIter& iter, const String& path) const;
00547          
00548         String get_string_from_iter(const TreeIter& iter) const;
00555 
00556         bool get_iter_first(TreeIter& iter) const;
00560         
00561         Pointer<TreePath> get_path(const TreeIter& iter) const;
00565 
00566         void get_value(const TreeIter& iter, int column, G::Value& value) const;
00571 
00572         String get_value(const TreeIter& iter, int column) const;
00577 
00578         bool get_value(const TreeIter& iter, int column, String& str) const;
00584 
00585         bool iter_has_child(const TreeIter& iter) const;
00587 
00591         
00592         template<typename DataType>
00593         void get_value(const TreeIter& iter, int column, DataType& data) const
00594         {
00595                 G::Value value;
00596                 gtk_tree_model_get_value(gtk_tree_model(), iter, column, value.g_value());
00597                 value.get(data);
00598         }
00607 
00608         template<typename DataType>
00609         void get_enum(const TreeIter& iter, int column, DataType& data) const
00610         {
00611                 G::Value value;
00612                 gtk_tree_model_get_value(gtk_tree_model(), iter, column, value.g_value());
00613                 int tmp_data;
00614                 value.get(tmp_data);
00615                 data = static_cast<DataType>(tmp_data);
00616         }
00626 
00627         template<typename DataType>
00628         void get_object(const TreeIter& iter, int column, DataType& data) const
00629         {
00630                 G::Value value;
00631                 gtk_tree_model_get_value(gtk_tree_model(), iter, column, value.g_value());
00632                 G::Object *object;
00633                 value.get(object);
00634                 data = static_cast<DataType>(object);
00635         }
00644 
00645         template<typename DataType>
00646         void get_pointer(const TreeIter& iter, int column, DataType& data) const
00647         {
00648                 G::Value value;
00649                 gtk_tree_model_get_value(gtk_tree_model(), iter, column, value.g_value());
00650                 void *tmp_data = 0;
00651                 value.get(tmp_data);
00652                 data = static_cast<DataType>(tmp_data);
00653         }
00664 
00668 
00669         bool iter_next(TreeIter& iter);
00675         
00676         bool iter_children(TreeIter& iter, const TreeIter *parent = 0);
00686         
00687         int iter_n_children(const TreeIter *iter);
00693          
00694         bool iter_nth_child(TreeIter& iter, const TreeIter *parent, int n);
00705         
00706         bool iter_parent(TreeIter& iter, const TreeIter& child);
00715 
00716         void ref_node(TreeIter *iter);
00728 
00729         void unref_node(TreeIter *iter);
00737 
00738         void foreach(const ForeachSlot *each);
00744 
00745         void row_changed(const TreePath& path, const TreeIter& iter);
00749          
00750         void row_inserted(const TreePath& path, const TreeIter& iter);
00754 
00755         void row_has_child_toggled(const TreePath& path, const TreeIter& iter);
00761         
00762         void row_deleted(const TreePath& path);
00769         
00770         void rows_reordered(const TreePath& path, const TreeIter& iter, int *new_order);
00778          
00782 
00783         const RowChangedSignalProxy sig_row_changed()
00784         {
00785                 return RowChangedSignalProxy(this, &row_changed_signal);
00786         }
00788 
00789         const RowInsertedSignalProxy sig_row_inserted()
00790         {
00791                 return RowInsertedSignalProxy(this, &row_inserted_signal);
00792         }
00794 
00795         const RowHasChildToggledSignalProxy sig_row_has_child_toggled()
00796         {
00797                 return RowHasChildToggledSignalProxy(this, &row_has_child_toggled_signal);
00798         }
00800 
00801         const RowDeletedSignalProxy sig_row_deleted()
00802         {
00803                 return RowDeletedSignalProxy(this, &row_deleted_signal);
00804         }
00806 
00807         const RowsReorderedSignalProxy sig_rows_reordered()
00808         {
00809                 return RowsReorderedSignalProxy(this, &rows_reordered_signal);
00810         }
00812         
00814 };
00815 
00822 
00823 class TreeRowReference : public G::Boxed
00824 {
00825 public:
00828 
00829         TreeRowReference(TreeModel& model, const TreePath& path);
00836         
00837         TreeRowReference(G::Object& proxy, TreeModel& model, const TreePath& path);
00850 
00851         explicit TreeRowReference(GtkTreeRowReference *reference);
00859 
00860         TreeRowReference(GtkTreeRowReference *reference, bool copy);
00872 
00873         TreeRowReference(const TreeRowReference& src);
00876         
00877         ~TreeRowReference();
00879 
00880         TreeRowReference& operator=(const TreeRowReference& src);
00883 
00887 
00888         GtkTreeRowReference* gtk_tree_row_reference() const { return (GtkTreeRowReference*)boxed_; }
00890 
00891         operator GtkTreeRowReference* () const;
00893 
00894         Pointer<TreePath> get_path() const;
00898         
00899         bool valid() const;
00902         
00904 
00905         static void inserted(const G::Object& proxy, const TreePath& path);
00910          
00911         static void deleted(const G::Object& proxy, const TreePath& path);
00916          
00917         static void reordered(const G::Object& proxy, const TreePath& path, const TreeIter& iter, int *new_order);
00924                 
00925 };
00926 
00927 } // namespace Gtk
00928 
00929 } // namespace Inti
00930 
00931 #endif // INTI_GTK_TREE_MODEL_H
00932 
Main Page - Footer


Generated on Sun Sep 14 20:08:04 2003 for Inti by doxygen 1.3.2 written by Dimitri van Heesch, © 1997-2002