/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 *
 * The contents of this file are subject to the Mozilla 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/MPL/
 *
 * 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):
 *   Chris Waterson <waterson@netscape.com>
 *   Ben Goodger <ben@netscape.com>
 *   Jan Varga <varga@ku.sk>
 *   Benjamin Smedberg <bsmedberg@covad.net>
 *
 * Alternatively, the contents of this file may be used under the terms of
 * either of 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 MPL, 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 MPL, the GPL or the LGPL.
 *
 * ***** END LICENSE BLOCK ***** */

#include "domstubs.idl"
#include "nsISupports.idl"
#include "nsIRDFCompositeDataSource.idl"
#include "nsIRDFResource.idl"

interface nsIXULBuilderListener;

[ptr] native nsIContent_ptr(nsIContent);

[scriptable, uuid(9da147a7-5854-49e3-a397-22ecdd93e96d)]
interface nsIXULTemplateBuilder : nsISupports
{
    /**
     * The ``root'' node in the DOM to which this builder is attached
     */
    readonly attribute nsIDOMElement root;

    /**
     * The composite datasource that the template builder observes
     * and uses to create content
     */
    readonly attribute nsIRDFCompositeDataSource database;

    /**
     * Force the template builder to rebuild its content.
     */
    void rebuild();

    /**
     * Reload any of our RDF datasources that support nsIRDFRemoteDatasource. 
     *
     * @note This is a temporary hack so that remote-XUL authors can
     *       reload remote datasources. When RDF becomes remote-scriptable,
     *       this will no longer be necessary.
     */
    void refresh();

    /**
     * Called to initialize a XUL content builder on a particular root
     * element. This element presumably has a ``datasources''
     * attribute, which the builder will parse to set up the template
     * builder's datasources.
     */
    [noscript] void init(in nsIContent_ptr aElement);

    /**
     * Invoked lazily by a XUL element that needs its child content
     * built.
     */
    [noscript] void createContents(in nsIContent_ptr aElement);

    /**
     * Add a listener to this template builder. The template builder
     * holds a strong reference to the listener.
     */
    void addListener(in nsIXULBuilderListener aListener);

    /**
     * Remove a listener from this template builder.
     */
    void removeListener(in nsIXULBuilderListener aListener);
};

/**
 * nsIXULTreeBuilderObserver
 *  This interface allows clients of the XULTreeBuilder to define domain 
 *  specific handling of specific nsITreeView methods that 
 *  XULTreeBuilder does not implement.
 */
[scriptable, uuid(a5480e0d-ac7c-42e5-aca5-d7f0bbffa207)]
interface nsIXULTreeBuilderObserver : nsISupports
{
    const long DROP_BEFORE = -1;
    const long DROP_ON = 0;
    const long DROP_AFTER = 1;
    /**
     * Methods used by the drag feedback code to determine if a drag is allowable at
     * the current location. To get the behavior where drops are only allowed on
     * items, such as the mailNews folder pane, always return false whe
     * the orientation is not DROP_ON.
     */
    boolean canDrop(in long index, in long orientation);

    /**
     * Called when the user drops something on this view. The |orientation| param
     * specifies before/on/after the given |row|.
     */
    void onDrop(in long row, in long orientation);
 
    /** 
     * Called when an item is opened or closed. 
     */
	  void onToggleOpenState (in long index);

    /** 
	 * Called when a header is clicked.
     */
    void onCycleHeader(in wstring colID, in nsIDOMElement elt);

    /**
     * Called when a cell in a non-selectable cycling column (e.g. 
     * unread/flag/etc.) is clicked.
     */
    void onCycleCell(in long row, in wstring colID);

    /** 
     * Called when selection in the tree changes
     */
    void onSelectionChanged();

    /**
     * A command API that can be used to invoke commands on the selection.  
     * The tree will automatically invoke this method when certain keys 
     * are pressed.  For example, when the DEL key is pressed, performAction 
     * will be called with the "delete" string. 
     */
    void onPerformAction(in wstring action);

    /**
     * A command API that can be used to invoke commands on a specific row.
     */
    void onPerformActionOnRow(in wstring action, in long row);

    /**
     * A command API that can be used to invoke commands on a specific cell.
     */
    void onPerformActionOnCell(in wstring action, in long row, in wstring colID);
};

[scriptable, uuid(06b31b15-ebf5-4e74-a0e2-6bc0a18a3969)]
interface nsIXULTreeBuilder : nsISupports
{
    /**
     * Retrieve the RDF resource associated with the specified row.
     */
    nsIRDFResource getResourceAtIndex(in long aRowIndex);

    /**
     * Retrieve the index associated with specified RDF resource.
     */
    long getIndexOfResource(in nsIRDFResource resource);

    /** 
     * Add a Tree Builder Observer to handle Tree View 
     * methods that the base builder does not implement. 
     */
    void addObserver(in nsIXULTreeBuilderObserver aObserver);

    /** 
     * Remove an Tree Builder Observer.
     */
    void removeObserver(in nsIXULTreeBuilderObserver aObserver);

    /** 
     * Sort the contents of the tree using the specified column.
     */
    void sort(in nsIDOMElement aColumnElement);
};

