#ifndef VISUAL_TREE_NODE_CLASS
#define VISUAL_TREE_NODE_CLASS

/*****************************************************************************\
*                                                                             *
*  Name   : visual_tree_node                                                  *
*  Author : Chris Koeritz                                                     *
*                                                                             *
*  Purpose:                                                                   *
*                                                                             *
*    One node in a visual tree.  Manages its own characteristics, such as     *
*  visibility and expansion.                                                  *
*                                                                             *
*******************************************************************************
* Copyright (c) 1998-$now By Author.  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 is online at:      *
*     http://www.fsf.org/copyleft/gpl.html                                    *
* Please send any updates to: fred@gruntose.com                               *
\*****************************************************************************/

#include "mfc_dll.h"

#include <nodes/tree.h>

// forward.
class tree_window;

class MFC_EXTENSIONS_CLASS_STYLE visual_tree_node : public nodes::tree
{
public:
  visual_tree_node(tree_window &container, visual_tree_node *parent,
         visual_tree_node *predecessor, const istring &text,
         int image_index = -1, int selected_image_index = -1);
    // creates a visual tree node with a "parent" node as the next higher node
    // in the tree.  if "parent" is NIL, then this node will be a root node.
    // if the "predecessor" is non-NIL, then this node will be listed after it
    // in the children of "parent".  if "predecessor" is not a child of
    // "parent", unknown phenomena may occur.  "image_index" specifies the
    // index into the image map of the containing tree that this node should
    // use for its appearance, or if it's negative, no image is used.  ditto
    // for "selected_image_index" which is the picture for an selected node.
  virtual ~visual_tree_node();

  enum closures { OPEN, CLOSED };
    // represents whether the node is open or closed.  this is only meaningful
    // for nodes that possess sub-nodes.

  closures closure() { return _closure; }
  void closure(closures new_state);
    // observes or modifies the expansion state.

  enum visibility { VISIBLE, INVISIBLE };
    // nodes can either be shown to the user or hidden from the user.

  visibility visible() { return _visible; }
  void visible(visibility new_state);
    // observes or modifies the visibility state.

  tree_window &container() const { return _trewink; }
    // allows the tree window that contains this node to be manipulated.

  void reset_images(int image_index = -1, int selected_image_index = -1);
    // changes the current images to "image_index" and "selected_image_index".

  virtual istring text() const;
    // returns the text string for this node.  note that if you modify
    // the os_node() object directly, this text will become out of date.
    // use the official set_text() method instead.  this method is virtual          // in case the text should be manipulated before displaying.  if you want       // that change to be reflected, you must call set_text() on the node after      // construction; this will cause the virtual method to be used.             

  void set_text(const istring &to_set);
    // changes the node's text to read as "to_set".

  HTREEITEM os_node() { return _os_node; }
    // allows the operating system's version of the visual node to be accessed.

  visual_tree_node *find_child(const istring &text_to_find);
    // looks for a child node of this tree node which has the "text_to_find"
    // as its visible text in the tree.

  visual_tree_node *attach(visual_tree_node *new_branch);
    // attaches the specified branch to the current tree in sorted order.
    // the return value is the node that came directly before the "new_branch"
    // or NIL if "new_branch" is now the first child.

  virtual void activate();
    // called when the tree node is activated by the user's double click.
    // the base class does nothing for this function; it must be overridden
    // for it to do anything interesting.

  virtual void context_menu();
    // called when the user selects a context menu on this node with a right
    // mouse button click.  the base function does nothing.

private:
  tree_window &_trewink;  // tree window that contains this node.
  closures _closure;  // current expansion state.
  visibility _visible;  // current visibility state.
  HTREEITEM _os_node;  // the link to the operating system's tree object.
  int _image_index;  // the image we use for this tree node.
  int _selected_index;  // image for an selected node.
  istring *_text;  // the text shown on the tree node.

  HTREEITEM add_item(HTREEITEM parent, const istring &text, HTREEITEM after);
    // adds an item to the tree where "parent" is the node to add the item
    // to, "text" is the caption for the item, and "after" is the existing
    // child of "parent" that the new item will be added after.

  // verboten:
  visual_tree_node(const visual_tree_node &);
  visual_tree_node &operator =(const visual_tree_node &);
};

#endif

