summaryrefslogtreecommitdiff
path: root/src/Fl_Tree.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'src/Fl_Tree.cxx')
-rw-r--r--src/Fl_Tree.cxx73
1 files changed, 44 insertions, 29 deletions
diff --git a/src/Fl_Tree.cxx b/src/Fl_Tree.cxx
index 03d3ccdff..a96ed2d6f 100644
--- a/src/Fl_Tree.cxx
+++ b/src/Fl_Tree.cxx
@@ -126,6 +126,8 @@ Fl_Tree_Item* Fl_Tree::add(const char *path) {
}
/// Inserts a new item above the specified Fl_Tree_Item, with the label set to 'name'.
+/// \param[in] above -- the item above which to insert the new item. Must not be NULL.
+/// \param[in] name -- the name of the new item
/// \returns the item that was added, or 0 if 'above' could not be found.
///
Fl_Tree_Item* Fl_Tree::insert_above(Fl_Tree_Item *above, const char *name) {
@@ -134,21 +136,21 @@ Fl_Tree_Item* Fl_Tree::insert_above(Fl_Tree_Item *above, const char *name) {
/// Insert a new item into a tree-item's children at a specified position.
///
-/// \param[in] item The existing item to insert new child into
+/// \param[in] item The existing item to insert new child into. Must not be NULL.
/// \param[in] name The label for the new item
/// \param[in] pos The position of the new item in the child list
-///
/// \returns the item that was added.
+///
Fl_Tree_Item* Fl_Tree::insert(Fl_Tree_Item *item, const char *name, int pos) {
return(item->insert(_prefs, name, pos));
}
/// Add a new child to a tree-item.
///
-/// \param[in] item The existing item to add new child to
+/// \param[in] item The existing item to add new child to. Must not be NULL.
/// \param[in] name The label for the new item
-///
/// \returns the item that was added.
+///
Fl_Tree_Item* Fl_Tree::add(Fl_Tree_Item *item, const char *name) {
return(item->add(_prefs, name));
}
@@ -160,12 +162,12 @@ Fl_Tree_Item* Fl_Tree::add(Fl_Tree_Item *item, const char *name) {
/// to do lookups without causing compiler errors.
///
/// \param[in] path -- the tree item's pathname to be found (eg. "Flintstones/Fred")
+/// \returns the item, or NULL if not found.
///
-/// \returns the item, or 0 if not found.
/// \see item_pathname()
///
Fl_Tree_Item *Fl_Tree::find_item(const char *path) {
- if ( ! _root ) return(0);
+ if ( ! _root ) return(NULL);
char **arr = parse_path(path);
Fl_Tree_Item *item = _root->find_item(arr);
free_path(arr);
@@ -174,7 +176,7 @@ Fl_Tree_Item *Fl_Tree::find_item(const char *path) {
/// A const version of Fl_Tree::find_item(const char *path)
const Fl_Tree_Item *Fl_Tree::find_item(const char *path) const {
- if ( ! _root ) return(0);
+ if ( ! _root ) return(NULL);
char **arr = parse_path(path);
const Fl_Tree_Item *item = _root->find_item(arr);
free_path(arr);
@@ -288,7 +290,6 @@ void Fl_Tree::draw() {
///
/// \param[in] item The item above/below which we'll find the next visible item
/// \param[in] dir The direction to search. Can be FL_Up or FL_Down.
-///
/// \returns The item found, or 0 if there's no visible items above/below the specified \p item.
///
Fl_Tree_Item *Fl_Tree::next_visible_item(Fl_Tree_Item *item, int dir) {
@@ -329,7 +330,7 @@ void Fl_Tree::set_item_focus(Fl_Tree_Item *item) {
/// \returns the item clicked, or 0 if no item was under the current event.
///
const Fl_Tree_Item* Fl_Tree::find_clicked() const {
- if ( ! _root ) return(0);
+ if ( ! _root ) return(NULL);
return(_root->find_clicked(_prefs));
}
@@ -368,8 +369,7 @@ Fl_Tree_Item* Fl_Tree::first() {
/// }
/// \endcode
///
-/// \param[in] item The item to use to find the next item. If NULL, returns NULL
-///
+/// \param[in] item The item to use to find the next item. If NULL, returns 0.
/// \returns Next item in tree, or 0 if at last item.
///
/// \see first(),next(),last(),prev()
@@ -389,8 +389,7 @@ Fl_Tree_Item *Fl_Tree::next(Fl_Tree_Item *item) {
/// }
/// \endcode
///
-/// \param[in] item The item to use to find the previous item. If NULL, returns NULL
-///
+/// \param[in] item The item to use to find the previous item. If NULL, returns 0.
/// \returns Previous item in tree, or 0 if at first item.
///
/// \see first(),next(),last(),prev()
@@ -450,7 +449,6 @@ Fl_Tree_Item *Fl_Tree::first_selected_item() {
/// \endcode
///
/// \param[in] item The item to use to find the next selected item. If NULL, first() is used.
-///
/// \returns The next selected item, or 0 if there are no more selected items.
///
Fl_Tree_Item *Fl_Tree::next_selected_item(Fl_Tree_Item *item) {
@@ -685,7 +683,8 @@ int Fl_Tree::handle(int e) {
/// The callback can use callback_item() and callback_reason() respectively to determine
/// the item changed and the reason the callback was called.
///
-/// \param[in] item The item that will be deselected (along with all its children)
+/// \param[in] item The item that will be deselected (along with all its children).
+/// If NULL, first() is used.
/// \param[in] docallback -- A flag that determines if the callback() is invoked or not:
/// - 0 - the callback() is not invoked
/// - 1 - the callback() is invoked for each item that changed state,
@@ -717,12 +716,11 @@ int Fl_Tree::deselect_all(Fl_Tree_Item *item, int docallback) {
/// the item changed and the reason the callback was called.
///
/// \param[in] item The item that will be selected (along with all its children).
-/// If NULL, first() is assumed.
+/// If NULL, first() is used.
/// \param[in] docallback -- A flag that determines if the callback() is invoked or not:
/// - 0 - the callback() is not invoked
/// - 1 - the callback() is invoked for each item that changed state,
/// callback_reason() will be FL_TREE_REASON_SELECTED
-///
/// \returns count of how many items were actually changed to the selected state.
///
int Fl_Tree::select_all(Fl_Tree_Item *item, int docallback) {
@@ -754,7 +752,6 @@ int Fl_Tree::select_all(Fl_Tree_Item *item, int docallback) {
/// - 1 - the callback() is invoked for each item that changed state,
/// callback_reason() will be either FL_TREE_REASON_SELECTED or
/// FL_TREE_REASON_DESELECTED
-///
/// \returns the number of items whose selection states were changed, if any.
///
int Fl_Tree::select_only(Fl_Tree_Item *selitem, int docallback) {
@@ -785,6 +782,9 @@ int Fl_Tree::select_only(Fl_Tree_Item *selitem, int docallback) {
/// the value will be clipped. So if yoff=100, but scrollbar's max
/// is 50, then 50 will be used.
///
+/// \param[in] item The item to be shown. Should not be NULL.
+/// \param[in] yoff The pixel offset from the top for the displayed position.
+///
/// \see show_item_top(), show_item_middle(), show_item_bottom()
///
void Fl_Tree::show_item(Fl_Tree_Item *item, int yoff) {
@@ -800,42 +800,57 @@ void Fl_Tree::show_item(Fl_Tree_Item *item, int yoff) {
/// This can be used to detect if the item is scrolled off-screen.
/// Checks to see if the item's vertical position is within the top and bottom
/// edges of the display window. This does NOT take into account the hide()/show()
-/// status of the item.
+/// or open()/close() status of the item.
+///
+/// \param[in] item The item to be checked. If NULL, first() is used.
+/// \returns 1 if displayed, 0 if scrolled off screen or no items are in tree.
///
int Fl_Tree::displayed(Fl_Tree_Item *item) {
- return( (item->y() >= y() && item->y() <= (y()+h()-item->h())) ? 1 : 0);
+ item = item ? item : first();
+ if (!item) return(0);
+ return( (item->y() >= y()) && (item->y() <= (y()+h()-item->h())) ? 1 : 0);
}
/// Adjust the vertical scroll bar to show \p item at the top
/// of the display IF it is currently off-screen (eg. show_item_top()).
/// If it is already on-screen, no change is made.
///
+/// \param[in] item The item to be shown. If NULL, first() is used.
+///
/// \see show_item_top(), show_item_middle(), show_item_bottom()
///
void Fl_Tree::show_item(Fl_Tree_Item *item) {
+ item = item ? item : first();
+ if (!item) return;
if ( displayed(item) ) return;
show_item_top(item);
}
/// Adjust the vertical scrollbar so that \p item is at the top of the display.
+///
+/// \param[in] item The item to be shown. If NULL, first() is used.
+///
void Fl_Tree::show_item_top(Fl_Tree_Item *item) {
item = item ? item : first();
- if ( ! item ) return;
- show_item(item, 0);
+ if (item) show_item(item, 0);
}
/// Adjust the vertical scrollbar so that \p item is in the middle of the display.
+///
+/// \param[in] item The item to be shown. If NULL, first() is used.
+///
void Fl_Tree::show_item_middle(Fl_Tree_Item *item) {
item = item ? item : first();
- if ( ! item ) return;
- show_item(item, h()/2 - item->h()/2);
+ if (item) show_item(item, (h()/2)-(item->h()/2));
}
/// Adjust the vertical scrollbar so that \p item is at the bottom of the display.
+///
+/// \param[in] item The item to be shown. If NULL, first() is used.
+///
void Fl_Tree::show_item_bottom(Fl_Tree_Item *item) {
item = item ? item : first();
- if ( ! item ) return;
- show_item(item, h() - item->h());
+ if (item) show_item(item, h()-item->h());
}
/// Returns the vertical scroll position as a pixel offset.
@@ -863,11 +878,11 @@ void Fl_Tree::vposition(int pos) {
}
/// Displays \p item, scrolling the tree as necessary.
-/// \param[in] item The item to be displayed.
+/// \param[in] item The item to be displayed. If NULL, first() is used.
///
void Fl_Tree::display(Fl_Tree_Item *item) {
- if ( ! item ) return;
- show_item_middle(item);
+ item = item ? item : first();
+ if (item) show_item_middle(item);
}
/**