/* Network-Integrated Multimedia Middleware (NMM)
 * http://www.motama.com/nmm.html
 *  
 * Copyright (C) 2006-2007
 * Motama GmbH, Saarbruecken, Germany
 * http://www.motama.com
 *  
 * This file is part of NMM. 
 * 
 * NMM 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; only version 2 of the License.      
 * 
 * NMM 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. See the GNU General Public 
 * License for more details.  
 * 
 * You should have received a copy of the GNU General Public License 
 * along with NMM; if not, write to the Free Software Foundation,    
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 */

#ifndef _NMM_TABLEUNIT_HPP_
#define _NMM_TABLEUNIT_HPP_ _NMM_TABLEUNIT_HPP_

#include "nmm/nmm_prefix.hpp"

#include "OSDElement.hpp"

#include "nmm/plugins/video/osd/manager/interfaces/ITextView.hpp"
#include "nmm/plugins/video/osd/manager/interfaces/IPlaneDecorator.hpp"
#include "nmm/plugins/video/osd/manager/interfaces/IBorderDecorator.hpp"
#include "nmm/plugins/video/osd/manager/interfaces/IScrollDecorator.hpp"
#include "nmm/plugins/video/osd/manager/interfaces/IHeaderDecorator.hpp"

namespace NMM {

  typedef list<unsigned int> ColumnList;
  
  /**
   *This Widget displays a table 
   */
  class TableUnit : public OSDElement {
  private:  
    ColumnList columns;
    bool scrollbarEnabled;

    void createWindows();
  public:
    
    TableUnit(IOSDManager* manager, IWidgetFactory* factory, string font);
    ~TableUnit();
        
    /** Spcify colors of this widget */
    void setColors( unsigned int win_active_color, unsigned int win_inactive_color,
                    unsigned int sel_active_color, unsigned int sel_active_color2, unsigned int sel_inactive_color );
    
    /** method to select the widget */
    void selectWindow( unsigned int mode=0 );
    /** method to deselect the widget */
    void deSelectWindow();
    /** set a text displayed above the widget */
    void setHeader( string h );
    
    /** set width of a specific column */
    void setColumnWidth( unsigned int c, unsigned int w );
    /** add a column with a specific width */
    void addColumn(unsigned int w);
    
    /** determine the selected line */
    unsigned int getSelectedLine();
    /** get the URL stored to line i */
    string getLineURL(const unsigned int& i);
    /** select line i */
    void selectLine(const unsigned int& i);
    /** deselct the line */
    void deSelectLine();
    /** slelect the line before the current one */
    Result selectUp();
    /** select the line after the current one */
    Result selectDown();

    /** get content of cell in line i and  column c */
    string getLineContent(const unsigned int& c, const unsigned int& i);
    /** get the whole content of line i */
    list<string> getLineContent(const unsigned int& i);
    /** set the content of cell in line i and column c */
    void setLineContent(const unsigned int c, const unsigned int i, string s);

    /** clears the widget */
    void deleteAllLines();
    /** add a line, fill it with the given strings and set the url*/
    unsigned int addLine(list<string> c,string url);
    /** add a line and fill it with the given strings*/
    unsigned int addLine(list<string> c);
    /** add a line, fill it with the given string and set the url*/
    unsigned int addLine(string c, string url);
    /** add a line, fill it with the given string */
    unsigned int addLine(string c);

    /** enable/disable display of scrollbar */
    void setScrollbarEnabled(bool enabled);
    /** asks, if the scrollbar is enabled */
    bool getScrollbarEnabled(){return scrollbarEnabled;}

    /** get the current number of lines of this widget */
    int getNumLines();
  protected:

    unsigned int  win_active_color;
    unsigned int  win_inactive_color;
    unsigned int  sel_active_color;
    unsigned int  sel_active_color2;
    unsigned int  sel_inactive_color;
    
    void deleteWidgets();
    
    string            font;
    
    list<ITextView*>     text;

    IWidgetComposite_var  composite;

    IPlaneDecorator_var   plane;
    IBorderDecorator_var  border;
    IScrollDecorator_var  scroll;
    IHeaderDecorator_var  header;
  };

}

#include "nmm/nmm_suffix.hpp"

#endif //_NMM_FLAGLISTUNIT_HPP_
