/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** 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) 2001
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *
 * 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 "nsISupports.idl"
#include "MailNewsTypes2.idl"

interface nsIMsgFolder;
interface nsIMsgWindow;
interface nsIMessenger;
interface nsIMsgDBHdr;
interface nsIMsgDBViewCommandUpdater;
interface nsIMsgDatabase;
interface nsIMsgSearchSession;
interface nsISimpleEnumerator;
interface nsITreeView;
interface nsIMsgCustomColumnHandler;

typedef long nsMsgViewNotificationCodeValue;
typedef long nsMsgViewCommandCheckStateValue;
typedef long nsMsgViewCommandTypeValue;
typedef long nsMsgNavigationTypeValue;

[scriptable, uuid(682a18be-fd18-11d4-a5be-0060b0fc04b7)]
interface nsMsgViewSortOrder
{
	const nsMsgViewSortOrderValue none = 0;
	const nsMsgViewSortOrderValue ascending = 1;
	const nsMsgViewSortOrderValue descending = 2;
};

[scriptable, uuid(f28a1cdf-06c3-4e98-8f66-f49991670071)]
interface nsMsgViewType {
    const nsMsgViewTypeValue eShowAllThreads = 0;
    const nsMsgViewTypeValue eShowThreadsWithUnread = 2;
    const nsMsgViewTypeValue eShowWatchedThreadsWithUnread = 3;
    const nsMsgViewTypeValue eShowQuickSearchResults = 4;
    const nsMsgViewTypeValue eShowVirtualFolderResults = 5;
    const nsMsgViewTypeValue eShowSearch = 6;
};

[scriptable, uuid(64852276-1dd2-11b2-8103-afe12002c053)]
interface nsMsgViewFlagsType
{
    /**
     * flags for GetViewFlags
     */
    const nsMsgViewFlagsTypeValue kNone = 0x0;
    const nsMsgViewFlagsTypeValue kThreadedDisplay = 0x1;
    const nsMsgViewFlagsTypeValue kShowIgnored = 0x8;
    const nsMsgViewFlagsTypeValue kUnreadOnly = 0x10;
    const nsMsgViewFlagsTypeValue kExpandAll = 0x20;
    const nsMsgViewFlagsTypeValue kGroupBySort = 0x40;
};

[scriptable, uuid(e8fdf9ca-9425-49de-b231-8d8fb51b8ee2)]
interface nsMsgViewSortType
{
  const nsMsgViewSortTypeValue byNone = 0x11; /* not sorted */
	const nsMsgViewSortTypeValue byDate = 0x12;
	const nsMsgViewSortTypeValue bySubject = 0x13;
	const nsMsgViewSortTypeValue byAuthor = 0x14;
	const nsMsgViewSortTypeValue byId = 0x15;
	const nsMsgViewSortTypeValue byThread = 0x16;
	const nsMsgViewSortTypeValue byPriority = 0x17;
	const nsMsgViewSortTypeValue byStatus = 0x18;
	const nsMsgViewSortTypeValue bySize = 0x19;
	const nsMsgViewSortTypeValue byFlagged = 0x1a;
	const nsMsgViewSortTypeValue byUnread = 0x1b;
	const nsMsgViewSortTypeValue byRecipient = 0x1c;
  const nsMsgViewSortTypeValue byLocation = 0x1d;
	const nsMsgViewSortTypeValue byTags = 0x1e;
	const nsMsgViewSortTypeValue byJunkStatus = 0x1f;
	const nsMsgViewSortTypeValue byAttachments = 0x20;
  const nsMsgViewSortTypeValue byAccount = 0x21;
  const nsMsgViewSortTypeValue byCustom = 0x22;
};

[scriptable, uuid(255d1c1e-fde7-11d4-a5be-0060b0fc04b7)]
interface nsMsgViewNotificationCode
{
  const nsMsgViewNotificationCodeValue none = 0;				
                  /* No change; this call is just being used
								   to potentially nest other sets of calls
								   inside it.  The "where" and "num" parameters
								   are unused. */
  const nsMsgViewNotificationCodeValue insertOrDelete = 1;		
                  /* Some lines have been inserted or deleted.
								   The "where" parameter will indicate
								   the first line that has been added or
								   removed; the "num" parameter will indicate
								   how many lines, and will be positive on
								   an insertion and negative on a deletion. */
  const nsMsgViewNotificationCodeValue changed = 2;			
                  /* Some lines have had their contents changed
								   (e.g., messages have been marked read
								   or something.)  "where" indicates the
								   first line with a change; "num" indicates
								   how many chaged. */
 const nsMsgViewNotificationCodeValue  scramble = 3;	
            		/* Everything changed.  Probably means we
								   resorted the folder.  We are still working
								   with the same set of items, or at least
								   have some overlap, but all the indices are
								   invalid.  The "where" and "num" parameters
								   are unused. */
  const nsMsgViewNotificationCodeValue all = 4;				/* Everything changed.  We're now not
								   displaying anything like what we were; we
								   probably opened a new folder or something.
								   The FE needs to forget anything it ever knew
								   about what was being displayed, and start
								   over.  The "where" and "num" parameters are
								   unused.  */
  const nsMsgViewNotificationCodeValue totalContentChanged = 5;
							    /* Introduced for the address book to support
								   virtual list views.  The total number of
								   entries on the LDAP directory has changed
								   and the FE must update its scrollbar.  The
								   "num" parameter contains the total number of
								   entries on the LDAP server. */
  const nsMsgViewNotificationCodeValue newTopIndex = 6;        
                    /* Introduced for the address book to support
								   virtual list views.  The virtual list view
								   cache data has changed and the FE view may
								   be out of date.  The view should be updated
								   so that the first/top index in the view is
								   the index in the "where" parameter.  The
								   scrollbar should be updated to match the new
								   position. */

};

[scriptable, uuid(4ec9248e-0108-11d5-a5be-0060b0fc04b7)]
interface nsMsgViewCommandCheckState
{
  const nsMsgViewCommandCheckStateValue notUsed = 0;
  const nsMsgViewCommandCheckStateValue checked = 1;
  const nsMsgViewCommandCheckStateValue unchecked = 2;
};

[scriptable, uuid(ad36e6cc-0109-11d5-a5be-0060b0fc04b7)]
interface nsMsgViewCommandType
{
  const nsMsgViewCommandTypeValue markMessagesRead = 0;
  const nsMsgViewCommandTypeValue markMessagesUnread = 1;
  const nsMsgViewCommandTypeValue toggleMessageRead = 2;
								   
  const nsMsgViewCommandTypeValue flagMessages = 3;
  const nsMsgViewCommandTypeValue unflagMessages = 4;

  const nsMsgViewCommandTypeValue toggleThreadWatched = 6;

  const nsMsgViewCommandTypeValue deleteMsg = 7;
  const nsMsgViewCommandTypeValue deleteNoTrash = 8;
  const nsMsgViewCommandTypeValue markThreadRead = 9;
  const nsMsgViewCommandTypeValue markAllRead = 10;
  const nsMsgViewCommandTypeValue expandAll = 11;
  const nsMsgViewCommandTypeValue collapseAll = 12;
  
  const nsMsgViewCommandTypeValue copyMessages = 13;
  const nsMsgViewCommandTypeValue moveMessages = 14;

  const nsMsgViewCommandTypeValue selectAll = 15;
  const nsMsgViewCommandTypeValue downloadSelectedForOffline = 16;
  const nsMsgViewCommandTypeValue downloadFlaggedForOffline = 17;

  const nsMsgViewCommandTypeValue selectThread = 18;
  const nsMsgViewCommandTypeValue selectFlagged = 19;
  const nsMsgViewCommandTypeValue cmdRequiringMsgBody = 20;
  const nsMsgViewCommandTypeValue label0 = 21;
  const nsMsgViewCommandTypeValue label1 = 22;
  const nsMsgViewCommandTypeValue label2 = 23;
  const nsMsgViewCommandTypeValue label3 = 24;
  const nsMsgViewCommandTypeValue label4 = 25;
  const nsMsgViewCommandTypeValue label5 = 26;
  const nsMsgViewCommandTypeValue lastLabel = 26;

  const nsMsgViewCommandTypeValue junk = 27;
  const nsMsgViewCommandTypeValue unjunk = 28;
  const nsMsgViewCommandTypeValue undeleteMsg = 29;

  const nsMsgViewCommandTypeValue applyFilters = 30;
  const nsMsgViewCommandTypeValue runJunkControls = 31;
  const nsMsgViewCommandTypeValue deleteJunk = 32;
};

[scriptable, uuid(65903eb2-1dd2-11b2-ac45-c5b69c1618d7)]
interface nsMsgNavigationType
{
  const nsMsgNavigationTypeValue firstMessage = 1;
  const nsMsgNavigationTypeValue nextMessage = 2;
  const nsMsgNavigationTypeValue previousMessage = 3;
  const nsMsgNavigationTypeValue lastMessage = 4;
  /**
   * must match nsMsgViewCommandTypeValue toggleThreadKilled
   */
  const nsMsgNavigationTypeValue toggleThreadKilled = 5;
  const nsMsgNavigationTypeValue firstUnreadMessage = 6;
  const nsMsgNavigationTypeValue nextUnreadMessage = 7;
  const nsMsgNavigationTypeValue previousUnreadMessage = 8;
  const nsMsgNavigationTypeValue lastUnreadMessage = 9;
  const nsMsgNavigationTypeValue nextUnreadThread = 10;
  const nsMsgNavigationTypeValue nextUnreadFolder = 11;
  const nsMsgNavigationTypeValue nextFolder = 12;
  const nsMsgNavigationTypeValue readMore = 13;
  /**
   * Go back to the previous visited message
   */
  const nsMsgNavigationTypeValue back = 15;
  /**
   * Go forward to the previous visited message 
   */
  const nsMsgNavigationTypeValue forward = 16;
  const nsMsgNavigationTypeValue firstFlagged = 17;
  const nsMsgNavigationTypeValue nextFlagged = 18;
  const nsMsgNavigationTypeValue previousFlagged = 19;
  const nsMsgNavigationTypeValue firstNew = 20;
  const nsMsgNavigationTypeValue editUndo = 21;
  const nsMsgNavigationTypeValue editRedo = 22;
};


[scriptable, uuid(7a49bcaa-5367-476d-a3da-7f305b7afb90)]
interface nsIMsgDBView : nsISupports
{
    void open(in nsIMsgFolder folder, in nsMsgViewSortTypeValue sortType, in nsMsgViewSortOrderValue sortOrder, in nsMsgViewFlagsTypeValue viewFlags, out long count);
    void openWithHdrs(in nsISimpleEnumerator aHeaders, in nsMsgViewSortTypeValue aSortType, 
                        in nsMsgViewSortOrderValue aSortOrder, 
                        in nsMsgViewFlagsTypeValue aViewFlags, out long aCount);
    void close();

    void init(in nsIMessenger aMessengerInstance, in nsIMsgWindow aMsgWindow, in nsIMsgDBViewCommandUpdater aCommandUpdater);

    void sort(in nsMsgViewSortTypeValue sortType, in nsMsgViewSortOrderValue sortOrder);

    void doCommand(in nsMsgViewCommandTypeValue command);
    void doCommandWithFolder(in nsMsgViewCommandTypeValue command, in nsIMsgFolder destFolder);
    void getCommandStatus(in nsMsgViewCommandTypeValue command,
						 out boolean selectable_p, out nsMsgViewCommandCheckStateValue selected_p);

    readonly attribute nsMsgViewTypeValue viewType;
    attribute nsMsgViewFlagsTypeValue viewFlags;
    attribute nsMsgViewSortTypeValue sortType;
    readonly attribute nsMsgViewSortOrderValue sortOrder;
    readonly attribute nsMsgKey keyForFirstSelectedMessage;
    readonly attribute nsMsgViewIndex viewIndexForFirstSelectedMsg;
    /**
     * this method will automatically expand the destination thread, 
     * if needs be. 
     */
    void viewNavigate(in nsMsgNavigationTypeValue motion, out nsMsgKey resultId, out nsMsgViewIndex resultIndex, out nsMsgViewIndex threadIndex, in boolean wrap);

    /**
     * Indicates if navigation of the passed motion type is valid. 
     */
    boolean navigateStatus(in nsMsgNavigationTypeValue motion);

    readonly attribute nsIMsgFolder msgFolder;
    attribute nsIMsgFolder viewFolder; // in the case of virtual folders, the VF db.

    nsMsgKey getKeyAt(in nsMsgViewIndex index);
    nsIMsgFolder getFolderForViewIndex(in nsMsgViewIndex index); // mainly for search
    string getURIForViewIndex(in nsMsgViewIndex index);
    nsIMsgDBView cloneDBView(in nsIMessenger aMessengerInstance, in nsIMsgWindow aMsgWindow, in nsIMsgDBViewCommandUpdater aCommandUpdater);
    void getURIsForSelection([array, size_is(count)] out string uris, out unsigned long count);
    void getIndicesForSelection([array, size_is(count)] out nsMsgViewIndex indices, out unsigned long count);

    readonly attribute string URIForFirstSelectedMessage;
    readonly attribute nsIMsgDBHdr hdrForFirstSelectedMessage;
    void loadMessageByMsgKey(in nsMsgKey aMsgKey);
    void loadMessageByViewIndex(in nsMsgViewIndex aIndex);
    void loadMessageByUrl(in string aUrl);
    void reloadMessage();
    void reloadMessageWithAllParts();

    readonly attribute unsigned long numSelected;
    readonly attribute nsMsgViewIndex msgToSelectAfterDelete; 
    readonly attribute nsMsgViewIndex currentlyDisplayedMessage; 

    // used by "go to folder" feature
	// and "remember last selected message" feature
	// if key is not found, we don't select.
    void selectMsgByKey(in nsMsgKey key);

    // we'll suppress displaying messages if the message pane is collapsed
    attribute boolean suppressMsgDisplay;

	// we'll suppress command updating during folder loading
	attribute boolean suppressCommandUpdating;

	//to notify tree that rows are going away
    void onDeleteCompleted(in boolean succeeded);

    readonly attribute nsIMsgDatabase db;

    readonly attribute boolean supportsThreading;

    attribute nsIMsgSearchSession searchSession;
    readonly attribute boolean removeRowOnMoveOrDelete; 

	nsMsgViewIndex findIndexFromKey(in nsMsgKey aMsgKey, in boolean aExpand);
    void ExpandAndSelectThreadByIndex(in nsMsgViewIndex aIndex, in boolean aAugment);

    // use lines or kB for size?
    readonly attribute boolean usingLines;
    
    // Custom Column Implementation note: see nsIMsgCustomColumnHandler
    
    // attaches a custom column handler to a specific column (can be a new column or a built in)
    void addColumnHandler(in AString aColumn, in nsIMsgCustomColumnHandler aHandler);
    
    // removes a custom column handler leaving the column to be handled by the system
    void removeColumnHandler(in AString aColumn);
    
    // returns the custom column handler attached to a specific column - if any
    nsIMsgCustomColumnHandler getColumnHandler(in AString aColumn);
};

/* this interface is rapidly morphing from a command updater interface into a more generic
   FE updater interface to handle changes in the view 
*/

[scriptable, uuid(65FC9AD5-0912-11d5-9901-001083010E9B)]
interface nsIMsgDBViewCommandUpdater : nsISupports
{
	/* Eventually we'll flush this out into some kind of rich interface
	   which may take specifc selection changed type notifications like
	   no selections, single selection, multi-selection, etc. For starters,
	   we are going to keep it generic. The back end will only push an update
	   command status when the # of selected items changes.
	*/

	void updateCommandStatus();

	/* displayed message has changed */
	void displayMessageChanged(in nsIMsgFolder aFolder, in wstring aSubject, in string aKeywords);

    /**
	 * allows the backend to tell the front end to re-determine 
	 * which message we should selet after a delete or move
	 */
	void updateNextMessageAfterDelete();
};
