#ifndef _KVI_SCRIPTTOOLBAR_DEFINITION_H_
#define _KVI_SCRIPTTOOLBAR_DEFINITION_H_
//=============================================================================
//
//   File : kvi_scripttoolbar_definition.h
//   Creation date : Fri Nov 08 2002 02:47:00 by Szymon Stefanek
//
//   This file is part of the KVirc irc client distribution
//   Copyright (C) 2002 Szymon Stefanek (pragma at kvirc dot net)
//
//   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 opinion) any later version.
//
//   This program 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 this program. If not, write to the Free Software Foundation,
//   Inc. ,59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
//=============================================================================

#include "kvi_settings.h"

#ifdef COMPILE_SCRIPTTOOLBAR

	#include "kvi_string.h"
	#include "kvi_list.h"
	#include "kvi_scripttoolbar_itemdefinition.h"
	
	#include <qasciidict.h>
	
	class KviScriptToolBar;
	class KviScriptToolBarManager;
	class KviConfig;
	class KviFrame;
	
	class KviScriptToolBarDefinition
	{
		friend class KviScriptToolBar;
		friend class KviScriptToolBarManager;
		friend class KviSingleScriptToolBarEditor;
	protected:
		KviScriptToolBarDefinition(KviScriptToolBarManager * pManager);
	public: // this should be protected but the QList template wants it public
		virtual ~KviScriptToolBarDefinition();
	protected:
		int                                          m_iId;       // globally unique id
		KviStr                                       m_szName;    // script name of this toolbar
		KviStr                                       m_szLabel;   // the label of this toolbar
		bool                                         m_bVisible;  // is this toolbar visible ?
		QAsciiDict<KviScriptToolBarItemDefinition> * m_pItems;    // the items in this toolbar
		KviPtrList<KviScriptToolBarItemDefinition> * m_pItemList; // the list of items (autodelete = false) serves for indexing
		KviPtrList<KviScriptToolBar>               * m_pToolBars; // existing toolbar instances
		KviScriptToolBarManager                    * m_pManager;
	protected:
		void setName(const KviStr &szName){ m_szName = szName; }; // can be set only by the toolbar manager
		void load(const char * szPrefix,KviConfig * cfg);         // called by the toolbar manager
		void save(const char * szPrefix,KviConfig * cfg);         // called by the toolbar manager
		void attach(KviScriptToolBar * pTb);                      // called by KviScriptToolBar constructor
		void detach(KviScriptToolBar * pTb);                      // called by KviScriptToolBar destructor
		void copyFrom(KviScriptToolBarDefinition * d);
		void storeVisibilityState();                              // called by KviScriptToolBarManager
	private:
		KviScriptToolBar * createInstance(KviFrame * pFrm);       // internal , called by instance()
	public:
		void rename(const KviStr &szNewName);
		KviPtrList<KviScriptToolBarItemDefinition> * itemList(){ return m_pItemList; }; // this is here for access by KviSingleScriptToolBarEditor
		int id(){ return m_iId; };
		KviScriptToolBar * existingInstance(KviFrame * pFrm);     // retrieves an instance of the bar for the frame pFrm if exists
		KviScriptToolBar * instance(KviFrame * pFrm);             // retrieves an instance of the bar for frame pFrm (creates it if needed)
		bool isVisible(){ return m_bVisible; };                   // is the toolbar "initally visible" ?
		//void setVisible(bool bVisible){ m_bVisible = bVisible; };
		void clear();
		const KviStr & name(){ return m_szName; };
		const KviStr & label(){ return m_szLabel; };
		void setLabel(const KviStr &szLabel);
		KviScriptToolBarItemDefinition * findItemDefinition(const KviStr & szName){ return m_pItems->find(szName.ptr()); };
		KviScriptToolBarItemDefinition * getItemDefinition(const KviStr & szName,KviScriptToolBarItemDefinition::Type t);
		void removeItemDefinition(const KviStr &szName){ m_pItems->remove(szName); };
		void generateKvsDefinition(KviStr &szBuffer);
	};

#endif // COMPILE_SCRIPTTOOLBAR

#endif // !_KVI_SCRIPTTOOLBAR_DEFINITION_H_
