/***************************************************************************

    supportware
    Copyright (C) 2001-2008 by c.holzheuer
    c.holzheuer@sourceworx.org

    This program 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; either version 2 of the License, or
    (at your option) any later version.

***************************************************************************/


#ifndef DDITEM_H
#define DDITEM_H

#include <ddmapptr.h>
#include <ddiobuffer.h>


using namespace std;

	
/// dditem 
/**

*/

class ddwebcgi;
class ddwebpage;
class dditem;


typedef ddmapptr<dditem> dditemptrmap;

class dditem : public ddbasenamedobject          
{

public:

	dditem();
	dditem( const ddstring& name );
  dditem( const ddstring& name, const ddstring& value, const ddstring& call="", size_t access=0 );
 
	dditem( const dditem& src );
	dditem& operator=( const dditem& src );
	virtual ~dditem();

	// factory aspekt
  virtual dditem* clone() const;
 
	// kind aspekt
  virtual size_t size();
	virtual dditem& operator[]( const ddstring& key );
	virtual dditem& operator[]( size_t index );
	virtual const dditem& operator[]( const ddstring& key ) const;
	virtual const dditem& operator[]( size_t index ) const;  	
	virtual void  add_child( dditem* item );	

	virtual bool contains_key( const ddstring& key ) const;
  virtual int index_of( const ddstring& key ) const;
 
	// wert aspekt
	virtual dditem& from_bool( bool value );
	virtual dditem& from_int( int value );
	virtual dditem& from_size_t( size_t value );
	virtual dditem& from_double( double value );
  virtual dditem& from_string( const ddstring& value, size_t asize = 0 );
	virtual dditem& set_field_value( const ddstring& key, const ddstring& value );
	virtual dditem& set_field_value( const ddstring& key, int value );
	
	virtual dditem& set_link( const ddstring& value, const ddstring& link, const ddstring& lclass="", const ddstring& title="" );
	
	virtual const ddstring& get_value() const;
  virtual const ddstring& get_param() const;
  virtual void  set_param( const ddstring& call );
	
	virtual dditem& set_visible( bool visible );
  virtual dditem& clear_value();	
  virtual dditem& clear_children();
  virtual ddstring to_string() const;
	virtual const char* data() const;
	
	// sections
	virtual const ddmapindex& get_index() const;	
	
  // io aspekt
	virtual void sync( ddwebcgi& cgi ); 
	virtual dd_result flush_content ( ddwebpage& pagelet ); 
	virtual dd_result flush_children( ddwebpage& pagelet, int from=0, int to=0 ); 
	virtual dd_result flush_content ( ddwebpage& pagelet, ddstring& target ); 
	virtual dd_result flush_children( ddwebpage& pagelet, ddstring& target, int from=0, int to=0 ); 
			
  // Zugriffsaspekt
  virtual size_t get_access();
  virtual void   set_access( size_t access );
  
	virtual ddstring join() const;	
	virtual void dump() const;
				
protected:

  size_t   _access;
  ddstring _value;
	ddstring _param;

};


/***************************************************************************

    supportware
    Copyright (C) 2001-2008 by c.holzheuer
    c.holzheuer@sourceworx.org

    This program 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; either version 2 of the License, or
    (at your option) any later version.

***************************************************************************/


class dditemcheckbox : public dditem          
{

friend class dditemboxstyle;

public:

	dditemcheckbox();
	dditemcheckbox( const ddstring& name );
  dditemcheckbox( const ddstring& name, const ddstring& value, const ddstring& call="", size_t access=0 );
 
	dditemcheckbox( const dditemcheckbox& src );
	virtual ~dditemcheckbox();

	// factory aspekt
  virtual dditem* clone() const;
  	// wert aspekt
	virtual dditem& from_bool( bool value );
	virtual dditem& from_int( int value );
	virtual dditem& from_size_t( size_t value );
	virtual dditem& from_double( double value );
  virtual dditem& from_string( const ddstring& value, size_t asize = 0 );
  
};




#endif
