// ---------------------------------------------------------------------------
// - HtmlTable.hpp                                                           -
// - afnix:www module - html table class definition                          -
// ---------------------------------------------------------------------------
// - This program is free software;  you can redistribute it  and/or  modify -
// - it provided that this copyright notice is kept intact.                  -
// -                                                                         -
// - This program  is  distributed in  the hope  that it will be useful, but -
// - without  any  warranty;  without  even   the   implied    warranty   of -
// - merchantability or fitness for a particular purpose.  In no event shall -
// - the copyright holder be liable for any  direct, indirect, incidental or -
// - special damages arising in any way out of the use of this software.     -
// ---------------------------------------------------------------------------
// - copyright (c) 1999-2006 amaury darsch                                   -
// ---------------------------------------------------------------------------

#ifndef  AFNIX_HTMLTABLE_HPP
#define  AFNIX_HTMLTABLE_HPP

#ifndef  AFNIX_OUTPUT_HPP
#include "Output.hpp"
#endif

#ifndef  AFNIX_PRINTTABLE_HPP
#include "PrintTable.hpp"
#endif

#ifndef  AFNIX_HTMLTR_HPP
#include "HtmlTr.hpp"
#endif

namespace afnix {
  
  /// The HtmlTable is a generic class used to produce dynamic html tables.
  /// The class is constructed as an array of rows. Each row accepts one or
  /// several data. The table is structured in three parts. The first part
  /// the table head. The second part or main part is the table body and the
  /// third part is the table foot.
  /// @author amaury darsch

  class HtmlTable : public HtmlElement {    
  protected:
    /// the default head tr class
    String d_htrc;
    /// the default body tr class
    String d_btrc;
    /// the default footer tr class
    String d_ftrc;
    /// the default head td class
    String d_htdc;
    /// the default body td class
    String d_btdc;
    /// the default footer td class
    String d_ftdc;
    /// the table caption
    String d_caption;
    /// the table head rows
    Vector d_thrs;
    /// the table body rows
    Vector d_tbrs;
    /// the table foot rows
    Vector d_tfrs;

  public:
    /// create an empty html table
    HtmlTable (void);

    /// create a table with a default tr class
    /// @param dtrc the default tr class
    HtmlTable (const String& dtrc);

    /// create a table with a default td and tr class
    /// @param dtrc the default tr class
    /// @param dtdc the default td class
    HtmlTable (const String& dtrc, const String& dtrc);

    /// create a table with a default class, td and tr class
    /// @param dtbc the default table class
    /// @param dtrc the default tr class
    /// @param dtdc the default td class
    HtmlTable (const String& dtbc, const String& dtrc, const String& dtrc);

    /// create a html table with a print table
    /// @param ptbl the print table to convert
    HtmlTable (const PrintTable& ptbl);

    /// @return the class name
    String repr (void) const;

    /// set the default head tr class
    /// @param dtrc the default tr class
    void sethtrc (const String& dtrc);

    /// @return the default head tr class
    String gethtrc (void) const;

    /// set the default body tr class
    /// @param dtrc the default tr class
    void setbtrc (const String& dtrc);

    /// @return the default body tr class
    String getbtrc (void) const;

    /// set the default footer tr class
    /// @param dtrc the default tr class
    void setftrc (const String& dtrc);

    /// @return the default footer tr class
    String getftrc (void) const;

    /// set the default head td class
    /// @param dtdc the default td class
    void sethtdc (const String& dtdc);

    /// @return the default head td class
    String gethtdc (void) const;

    /// set the default body td class
    /// @param dtdc the default td class
    void setbtdc (const String& dtdc);

    /// @return the default body td class
    String getbtdc (void) const;

    /// set the default footer td class
    /// @param dtdc the default td class
    void setftdc (const String& dtdc);

    /// @return the default ooter td class
    String getftdc (void) const;

    /// set the table caption
    /// @param caption the caption to set
    void setcaption (const String& caption);

    /// @return the table caption
    String getcaption (void) const;

    /// @return the head length
    long gethlen (void) const;

    /// @return the body length
    long getblen (void) const;

    /// @return the foot length
    long getflen (void) const;

    /// @return a head table row by index
    HtmlTr* gethtr (const long index) const;

    /// @return a body table row by index
    HtmlTr* getbtr (const long index) const;

    /// @return a footer table row by index
    HtmlTr* getftr (const long index) const;

    /// add a row to the table head
    /// @param tr the table row to add
    void addhead (HtmlTr* tr);

    /// add a row to the table body
    /// @param tr the table row to add
    void addbody (HtmlTr* tr);

    /// add a row to the table foot
    /// @param tr the table row to add
    void addfoot (HtmlTr* tr);

    /// add a print table in this table
    /// @param ptbl the print table used for update
    void addtbl (const PrintTable& ptbl);

    /// emit the table into a buffer
    /// @param buf the recepting buffer
    void emit (Buffer& buf) const;

  private:
    // make the copy constructor private
    HtmlTable (const HtmlTable&);
    // make the assignment operator private
    HtmlTable& operator = (const HtmlTable&);

  public:
    /// create a new object in a generic way
    /// @param argv the argument vector
    static Object* mknew (Vector* argv);

    /// @return true if the given quark is defined
    bool isquark (const long quark, const bool hflg) const;

    /// apply this object with a set of arguments and a quark
    /// @param robj  the current runnable
    /// @param nset  the current nameset    
    /// @param quark the quark to apply these arguments
    /// @param argv  the arguments to apply
    Object* apply (Runnable* robj, Nameset* nset, const long quark,
                   Vector* argv);
  };
}

#endif
