/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
 * Version: NPL 1.1/GPL 2.0/LGPL 2.1
 *
 * The contents of this file are subject to the Netscape Public License
 * Version 1.1 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://www.mozilla.org/NPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is mozilla.org code.
 *
 * The Initial Developer of the Original Code is 
 * Netscape Communications Corporation.
 * Portions created by the Initial Developer are Copyright (C) 1998
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 * Original Author: David W. Hyatt (hyatt@netscape.com)
 *  Ben Goodger <ben@netscape.com>
 *
 * Alternatively, the contents of this file may be used under the terms of
 * either the GNU General Public License Version 2 or later (the "GPL"), or 
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 * in which case the provisions of the GPL or the LGPL are applicable instead
 * of those above. If you wish to allow use of your version of this file only
 * under the terms of either the GPL or the LGPL, and not to allow others to
 * use your version of this file under the terms of the NPL, indicate your
 * decision by deleting the provisions above and replace them with the notice
 * and other provisions required by the GPL or the LGPL. If you do not delete
 * the provisions above, a recipient may use your version of this file under
 * the terms of any one of the NPL, the GPL or the LGPL.
 *
 * ***** END LICENSE BLOCK ***** */

#include "nsISupports.idl"
#include "domstubs.idl"

interface nsITreeView;
interface nsITreeSelection;
interface nsIDOMEvent;

[scriptable, uuid(44481385-B1DA-480a-9026-1F0232C4EE59)]
interface nsITreeBoxObject : nsISupports
{
  /**
   * The view that backs the tree and that supplies it with its data.
   * It is dynamically settable, either using a view attribute on the
   * tree tag or by setting this attribute to a new value.
   */
  attribute nsITreeView view;

  /**
   * Whether or not we are currently focused.
   */
  attribute boolean focused;

  /**
   * Obtain the treebody content node
   */
  readonly attribute nsIDOMElement treeBody;

  /**
   * Obtains the selection from the view.
   */
  readonly attribute nsITreeSelection selection;

  /**
   * Obtain the height of a row.
   */
  readonly attribute long rowHeight;

  /**
   * Get the index of the specified column.
   */
  long getColumnIndex(in wstring colID);

  /**
   * Get the ID of the specified column.
   */
  AString getColumnID(in long colIndex);

  /**
   * Get the index of the primary column.
   */
  long getKeyColumnIndex();

  /**
   * Get the index of the first visible row.
   */
  long getFirstVisibleRow();

  /**
   * Get the index of the last visible row.
   */
  long getLastVisibleRow();

  /**
   * Gets the number of possible visible rows.
   */
  long getPageCount();

  /**
   * Ensures that a row at a given index is visible.
   */
  void ensureRowIsVisible(in long index);

  /**
   * Scrolls such that the row at index is at the top of the visible view.
   */
  void scrollToRow(in long index);

  /**
   * Scroll the tree up or down by numLines lines. Positive
   * values move down in the tree. Prevents scrolling off the
   * end of the tree. 
   */
  void scrollByLines(in long numLines);

  /**
   * Scroll the tree up or down by numPages pages. A page
   * is considered to be the amount displayed by the tree.
   * Positive values move down in the tree. Prevents scrolling
   * off the end of the tree.
   */
  void scrollByPages(in long numPages);
  
  /**
   * Invalidation methods for fine-grained painting control.
   */
  void invalidate();
  void invalidateColumn(in wstring colID);
  void invalidateRow(in long index);
  void invalidateCell(in long row, in wstring colID);
  void invalidatePrimaryCell(in long row);
  void invalidateRange(in long startIndex, in long endIndex);

  /**
   * A hit test that can tell you what row the mouse is over.
   * returns -1 for invalid mouse coordinates.
   */
  long getRowAt(in long x, in long y);

  /**
   * A hit test that can tell you what cell the mouse is over.  Row is the row index
   * hit,  returns -1 for invalid mouse coordinates.  ColID is the column hit.
   * ChildElt is the pseudoelement hit: this can have values of
   * "cell", "twisty", "image", and "text".
   */
  void getCellAt(in long x, in long y, out long row, out wstring colID, out wstring childElt);

  /** 
   * Find the coordinates of an element within a specific cell. 
   */
  void getCoordsForCellItem(in long row, in wstring colID, in wstring element, 
                            out long x, out long y, out long width, out long height);

  /** 
   * Determine if the text of a cell is being cropped or not.
   */
  boolean isCellCropped(in long row, in AString colID);

  /**
   * The view is responsible for calling these notification methods when
   * rows are added or removed.  Index is the position at which the new
   * rows were added or at which rows were removed.  For
   * non-contiguous additions/removals, this method should be called multiple times.
   */
  void rowCountChanged(in long index, in long count);
  
  /**
   * Notify the tree that the view is about to perform a batch
   * update, that is, add, remove or invalidate several rows at once.
   * This must be followed by calling endUpdateBatch(), otherwise the tree
   * will get out of sync.
   */
  void beginUpdateBatch();

  /**
   * Notify the tree that the view has completed a batch update.
   */
  void endUpdateBatch();

  /**
   * Drag handlers, installed from XBL, called when drags occur to handle painting
   */
  void onDragEnter ( in nsIDOMEvent event ) ;
  void onDragExit ( in nsIDOMEvent event ) ;
  void onDragOver ( in nsIDOMEvent event)  ;
  void onDragDrop ( in nsIDOMEvent event ) ;
  
  /**
   * Called on a theme switch to flush out the tree's style and image caches.
   */
  void clearStyleAndImageCaches();
};

%{C++
// Initializer,
%}

