1 //
2 // "$Id$"
3 //
4 
5 #ifndef _FL_TREE_ITEM_ARRAY_H
6 #define _FL_TREE_ITEM_ARRAY_H
7 
8 #include <FL/Fl.H>
9 #include "Fl_Export.H"
10 
11 class Fl_Tree_Item;		// forward decl must *precede* first doxygen comment block
12 				// or doxygen will not document our class..
13 
14 //////////////////////////
15 // FL/Fl_Tree_Item_Array.H
16 //////////////////////////
17 //
18 // Fl_Tree -- This file is part of the Fl_Tree widget for FLTK
19 // Copyright (C) 2009-2010 by Greg Ercolano.
20 //
21 // This library is free software. Distribution and use rights are outlined in
22 // the file "COPYING" which should have been included with this file.  If this
23 // file is missing or damaged, see the license at:
24 //
25 //     http://www.fltk.org/COPYING.php
26 //
27 // Please report all bugs and problems on the following page:
28 //
29 //     http://www.fltk.org/str.php
30 //
31 
32 ///
33 /// \file
34 /// \brief This file defines a class that manages an array of Fl_Tree_Item pointers.
35 ///
36 
37 /// \brief Manages an array of Fl_Tree_Item pointers.
38 ///
39 /// Because FLTK 1.x.x. has mandated that templates and STL not be used,
40 /// we use this class to dynamically manage the arrays.
41 ///
42 /// None of the methods do range checking on index values; the caller
43 /// must be sure that index values are within the range 0<index<total()
44 /// (unless otherwise noted).
45 ///
46 
47 class FL_EXPORT Fl_Tree_Item_Array {
48   Fl_Tree_Item **_items;	// items array
49   int _total;			// #items in array
50   int _size;			// #items *allocated* for array
51   int _chunksize;		// #items to enlarge mem allocation
52 #if FLTK_ABI_VERSION >= 10303
53   enum {
54     MANAGE_ITEM = 1,		///> manage the Fl_Tree_Item's internals (internal use only)
55   };
56   char _flags;			// flags to control behavior
57 #endif
58   void enlarge(int count);
59 public:
60   Fl_Tree_Item_Array(int new_chunksize = 10);		// CTOR
61   ~Fl_Tree_Item_Array();				// DTOR
62   Fl_Tree_Item_Array(const Fl_Tree_Item_Array *o);	// COPY CTOR
63   /// Return the item and index \p i.
64   Fl_Tree_Item *operator[](int i) {
65     return(_items[i]);
66   }
67   /// Const version of operator[](int i)
68   const Fl_Tree_Item *operator[](int i) const {
69     return(_items[i]);
70   }
71   /// Return the total items in the array, or 0 if empty.
total()72   int total() const {
73     return(_total);
74   }
75   /// Swap the two items at index positions \p ax and \p bx.
76 #if FLTK_ABI_VERSION >= 10301
77   // NEW -- code moved to .cxx
78   void swap(int ax, int bx);
79 #else /*FLTK_ABI_VERSION*/
80   // OLD
swap(int ax,int bx)81   void swap(int ax, int bx) {
82     Fl_Tree_Item *asave = _items[ax];
83     _items[ax] = _items[bx];
84     _items[bx] = asave;
85   }
86 #endif /*FLTK_ABI_VERSION*/
87   int move(int to, int from);
88   int deparent(int pos);
89   int reparent(Fl_Tree_Item *item, Fl_Tree_Item *newparent, int pos);
90   void clear();
91   void add(Fl_Tree_Item *val);
92   void insert(int pos, Fl_Tree_Item *new_item);
93   void replace(int pos, Fl_Tree_Item *new_item);
94   void remove(int index);
95   int  remove(Fl_Tree_Item *item);
96 #if FLTK_ABI_VERSION >= 10303
97   /// Option to control if Fl_Tree_Item_Array's destructor will also destroy the Fl_Tree_Item's.
98   /// If set: items and item array is destroyed.
99   /// If clear: only the item array is destroyed, not items themselves.
manage_item_destroy(int val)100   void manage_item_destroy(int val) {
101     if ( val ) _flags |= MANAGE_ITEM; else _flags &= ~MANAGE_ITEM;
102   }
manage_item_destroy()103   int manage_item_destroy() const {
104     return _flags & MANAGE_ITEM ? 1 : 0;
105   }
106 #endif
107 };
108 
109 #endif /*_FL_TREE_ITEM_ARRAY_H*/
110 
111 //
112 // End of "$Id$".
113 //
114