/* 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_WGTEXTVIEW_HPP_
#define _NMM_WGTEXTVIEW_HPP_ _NMM_WGTEXTVIEW_HPP_

#include "nmm/nmm_prefix.hpp"

#include "Widget.hpp"
#include "TextDraw.hpp"

#include "interfaces/ITextViewImpl.hpp"

namespace NMM {
  
  /**
   * Text view widget.
   */
  class TextView : virtual public Widget,
                   virtual public ITextViewImpl {
    
  public:
    typedef struct {
      string text;
      string url;
      void* common;
    } content_t;
    
    typedef vector<content_t> line_t;
    
  protected:
    /** font that is used to draw the text */
    BitmapFont*    font;
    
    /** class that contains some functions to draw text */
    TextDraw       textdraw;
    
    /** list of lines */
    line_t         lines;
    
    /** selected line (0 if no line is selected) */
    unsigned int   selected_line;
    
    /** selected second line (for highlight) */
    unsigned int   selected_line2;
    
    /** selection color */
    unsigned int   selection_color;
    
    /** selection color2 (for second highlight) */
    unsigned int   selection_color2;
    
    /** first visible line */
    unsigned int   start_line;
    
    /** number of visible lines */
    unsigned int   max_lines;
    
    /** indicates whether a focusSelection() Call should happen when calling selectLine() */
    bool           autofocus;
    
    /** space(pixels) between 2 lines */
    unsigned int   line_space;
    
    list<unsigned int> marked_lines;
  public:
    TextView();
    virtual ~TextView();
    
    /** IScrollable interface. */
    virtual nmm_int32 getScrollBarYPosition() const;
    virtual nmm_int32 getScrollBarHeight() const;
    
    /** ITextView interface. */
    virtual void selectUp();
    virtual void selectDown();
    virtual void setFont(const string& value);
    virtual nmm_uint32 selectLine(const nmm_uint32& line);
    virtual nmm_uint32 selectLine2(const nmm_uint32& line);
    virtual void deSelectLine();
    virtual void deSelectLine2();
    virtual nmm_uint32 getSelectedLine() const;
    virtual nmm_uint32 getSelectedLine2() const;
    virtual string getLineContent(const nmm_uint32& line) const;
    virtual string getLineURL(const nmm_uint32& line) const;
    virtual IWidget* getLineWidget(const nmm_uint32& line) const;
    virtual void setAutoFocus(const nmm_bool& value);
    virtual void setSelectionColor(const nmm_uint32& color);
    virtual void setSelectionColor2(const nmm_uint32& color);
    virtual void reset();
    virtual void setMaxLines(const nmm_uint32& value);
    virtual nmm_uint32 getMaxLines() const;
    virtual nmm_uint32 setStartLine(const nmm_uint32& start);
    virtual nmm_uint32 getStartLine() const;
    virtual nmm_uint32 getNumLines() const;
    virtual void focusSelection();
    virtual void insertLine(const nmm_int32& pos, const string& text, const string& url = "");
    virtual nmm_int32 addLine(const string& text, const string& url = "");
    virtual void addLineWidget(const nmm_uint32& line, const IWidget& widget);
    virtual void deleteLine(const nmm_uint32& line);
    virtual void deleteAllLines();
    virtual void changeLineContent(const nmm_uint32& line, const string& text);
    
    virtual void markLine(const nmm_uint32& line);
    virtual void unmarkLine(const nmm_uint32& line);
    virtual list<nmm_uint32> getMarkedLines();

    /**
     * Add internal line.
     * @param con line content
     * @return line number
     */
    int add( content_t con );
    
    /**
     * Insert internal line.
     * @param pos position to insert at
     * @param con line content
     */
    void insert( int pos, content_t con );
    
    /**
     * Get internal line.
     * @param line linenumberListUnit::
     * @return content of that line
     */
    content_t& getLine( unsigned int line );
    
    /**
     * Set space (pixels) between 2 lines.
     * (initial value is taken from font object)
     */
    void setLineSpace( unsigned int ls );
    
    /** Get line space. */
    unsigned int getLineSpace();
    
    void draw( workspace_t* ws );

  }; // TextView

}

#include "nmm/nmm_suffix.hpp"

#endif //_NMM_WGTEXTVIEW_HPP_
