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

    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 DDWEBRENDERER_H
#define DDWEBRENDERER_H

#include <dddatatable.h>
#include <dddataobject.h>
#include <ddwebrendertag.h>

class ddiobuffer;
class ddwebpage;
class ddwebrenderer;
class ddwebrendererpos;

typedef void (ddwebrenderer:: *ddwebrenderercall)( dditem&, dddatastaterow&, const ddstring& value );
typedef map<ddstring,ddwebrenderercall> ddwebrenderercallmap;


/// ddwebrendererpos: Hilfsstruktur für den Renderer
/**
	Struktur zum speichern von Quell- und Zielposition beim Feldkopieren
*/

class ddwebrendererpos
{

public: 

	ddwebrendererpos()
	: target( 0 ), src( 0 ), call( 0 )
	{
	}
	
	ddwebrendererpos( int atarget, int asrc, ddwebrenderercall acall=0 )
	: target( atarget ), src( asrc ), call( acall )
	{
	}
	
	int		 						target, src;
	ddwebrenderercall	call;

};

typedef vector<ddwebrendererpos> ddwebrendererposvec;



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

    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.

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


/// Doch wieder eine eigene Klasse: der renderer
/**
	Ex itemsync, ex snitemsync, ex ddwebsync :-)
*/

class ddwebrenderer
{

public:
    
	ddwebrenderer();
  virtual ~ddwebrenderer();
	
	inline void clear_entries()
	{
		_entries.clear();		
	}
	
	inline void clear_result()
	{
		_value = "";		
	}
		
	
	inline ddstring get_result() const
	{
		return _value;		 
	}

	
	inline void init_tag_blocks( ddconfig& config )
	{
		_tagblocks.init_tag_blocks( config );
	}
	
	
	virtual ddstring render( ddwebpage& pagelet, dditem& target, ddwebview& source, int from=0, int to=0 );
	virtual ddstring render_entry( ddwebpage& pagelet, dditem& target, dddatastaterow& row, int rowidx, bool doinit=false );
	
protected:	
	
	void 			init_positions( dditem& target, ddstringrow& row );

	ddstring	get_thread_link( dddatastaterow& src );
	ddstring	get_image_url( dddatastaterow& src, const ddstring& blockname );
	
	
	// neu
	virtual void render_number 						( dditem& item, dddatastaterow& src, const ddstring& value );		
	virtual void render_hitcount					( dditem& item, dddatastaterow& src, const ddstring& value );		
	virtual void render_answercount			 	( dditem& item, dddatastaterow& src, const ddstring& value );		
	
	virtual void render_msgteaser  				( dditem& item, dddatastaterow& src, const ddstring& value );
	virtual void render_user_is_owner			( dditem& item, dddatastaterow& src, const ddstring& value );	
	virtual void render_state_bits				( dditem& item, dddatastaterow& src, const ddstring& value );	
	
	
	
	
	// to be cleaned up ...
	virtual void render_group_link 				( dditem& item, dddatastaterow& src, const ddstring& value );
	virtual void render_group_link_nl			( dditem& item, dddatastaterow& src, const ddstring& value );	
	virtual void render_member_link				( dditem& item, dddatastaterow& src, const ddstring& value );
	virtual void render_member_link_nl		( dditem& item, dddatastaterow& src, const ddstring& value );	
	
	virtual void render_pager_indent 			( dditem& item, dddatastaterow& src, const ddstring& value );
	virtual void render_pager_jump_last		( dditem& item, dddatastaterow& src, const ddstring& value );	
	virtual void render_navi_jmp	 				( dditem& item, dddatastaterow& src, const ddstring& value );
	virtual void render_navi_com	 				( dditem& item, dddatastaterow& src, const ddstring& value );
	virtual void render_recipe_ing 				( dditem& item, dddatastaterow& src, const ddstring& value );
	virtual void render_icon_link					( dditem& item, dddatastaterow& src, const ddstring& value );
	virtual void render_icon_link_news		( dditem& item, dddatastaterow& src, const ddstring& value );
	
	virtual void render_threadlink 				( dditem& item, dddatastaterow& src, const ddstring& value );
	virtual void render_threadbase 				( dditem& item, dddatastaterow& src, const ddstring& value );
	virtual void render_count			 				( dditem& item, dddatastaterow& src, const ddstring& value );
	virtual void render_block_admin				( dditem& item, dddatastaterow& src, const ddstring& value );
	virtual void render_block_vote 				( dditem& item, dddatastaterow& src, const ddstring& value );
	virtual void render_block_options			( dditem& item, dddatastaterow& src, const ddstring& value );
	virtual void render_member_icon				( dditem& item, dddatastaterow& src, const ddstring& value );
	virtual void render_teaser_image			( dditem& item, dddatastaterow& src, const ddstring& value );
	virtual void render_teaser_flat				( dditem& item, dddatastaterow& src, const ddstring& value );
	
	virtual void render_member_is_online	( dditem& item, dddatastaterow& src, const ddstring& value );
	virtual void render_homepage_short		( dditem& item, dddatastaterow& src, const ddstring& value );
	virtual void render_jump_last					( dditem& item, dddatastaterow& src, const ddstring& value );
	virtual void render_ad_include				( dditem& item, dddatastaterow& src, const ddstring& value );
	
	// neu
	virtual void render_bbcode_block			( dditem& item, dddatastaterow& src, const ddstring& value );
		
	ddwebpage*							_pagelet;
	dditem* 								_target; 
	ddwebview* 							_source;
	int											_visibleidx, _realidx;
	bool										_is_admin;
	ddwebrendererposvec			_entries;
	ddwebrenderercallmap		_callmap;
	ddstring    						_value;
	int											_adincluderatio;
	int											_maxadincludes;
	int											_adincludecount;
	ddwebrendertagblockmap	_tagblocks;
	
		
};




#endif
