#ifndef __lib_service_listboxservice_h
#define __lib_service_listboxservice_h

#include <lib/gui/elistbox.h>
#include <lib/gui/elistboxcontent.h>
#include <lib/service/iservice.h>
#include <set>

class eListboxServiceContent: public virtual eListboxPythonMultiContent
{
	SWIG_AUTODOC
	DECLARE_REF(eListboxServiceContent);
public:
	eListboxServiceContent();

	void addService(const eServiceReference &ref, bool beforeCurrent=false);
	void removeCurrent();
	void FillFinished();

	void setRoot(const eServiceReference &ref, bool justSet=false);
	void getCurrent(eServiceReference &ref);

	int getNextBeginningWithChar(char c);
	int getPrevMarkerPos();
	int getNextMarkerPos();
	
		/* support for marked services */
	void initMarked();
	void addMarked(const eServiceReference &ref);
	void removeMarked(const eServiceReference &ref);
	int isMarked(const eServiceReference &ref);

		/* this is NOT thread safe! */
	void markedQueryStart();
	int markedQueryNext(eServiceReference &ref);

	int lookupService(const eServiceReference &ref);
	void setCurrent(const eServiceReference &ref);

	void sort();

	int setCurrentMarked(bool);
	bool isCurrentMarked();

	/* hack for channel numbers in bouquets */
	int getNumMarkersBeforeCurrent();

protected:
	void cursorHome();
	void cursorEnd();
	int cursorMove(int count=1);
	int cursorValid();
	int cursorSet(int n);
	int cursorGet();

	void cursorSave();
	void cursorRestore();
	int size();

private:
	ePyObject getCurrent(); // eListboxPythonMultiContent::getCurrent!

	typedef std::list<eServiceReference> list;

	list m_list;
	list::iterator m_cursor, m_saved_cursor;

	int m_cursor_number, m_saved_cursor_number;
	int m_size;

	eSize m_itemsize;
	ePtr<iServiceHandler> m_service_center;
	ePtr<iListableService> m_lst;

	eServiceReference m_root;

		/* support for marked services */
	std::set<eServiceReference> m_marked;
	std::set<eServiceReference>::const_iterator m_marked_iterator;

		/* support for movemode */
	bool m_current_marked;

	eServiceReference m_is_playable_ignore;
};

#endif
