//	Zinc Application Framework - Z_LANG.HPP
//	COPYRIGHT (C) 1990-1999.  All Rights Reserved.
//	Zinc Software Incorporated.  Pleasant Grove, Utah  USA

#if !defined(Z_LANG_HPP)
#define Z_LANG_HPP
#include <z_data.hpp>
#include <z_str.hpp>

// --------------------------------------------------------------------------
// ----- ZafMessageStruct ---------------------------------------------------
// --------------------------------------------------------------------------

struct ZAF_EXPORT ZafMessageStruct
{
	ZafIChar *text;
	ZafNumberID numberID;
	ZafIChar *stringID;
	ZafIChar hotKeyChar;
	int hotKeyIndex;
};

// --------------------------------------------------------------------------
// ----- ZafMessageData -----------------------------------------------------
// --------------------------------------------------------------------------

class ZAF_EXPORT ZafMessageData : public ZafStringData
{
public:
	// -- General members ---
	ZafMessageData(const ZafIChar *value, ZafIChar hotKeyChar = 0, int index = -1);

	// Hot key info.
	ZafIChar HotKeyChar(void) const;
	int HotKeyIndex(void) const;
	virtual ZafIChar SetHotKey(ZafIChar hotKeyChar, int index = -1);

	// --- Class identification ---
	static ZafClassID classID;
	static ZafClassNameChar ZAF_FARDATA className[];
	virtual ZafClassID ClassID(void) const { return (classID); }
	virtual ZafClassName ClassName(void) const { return (className); }
	virtual bool IsA(ZafClassID compareID) const;
	virtual bool IsA(ZafClassName compareName) const;

protected:
	ZafIChar hotKeyChar;
	int hotKeyIndex;
};

inline ZafIChar ZafMessageData::HotKeyChar(void) const { return (hotKeyChar); }
inline int ZafMessageData::HotKeyIndex(void) const { return (hotKeyIndex); }

// --------------------------------------------------------------------------
// ----- ZafLanguageData ----------------------------------------------------
// --------------------------------------------------------------------------

class ZAF_EXPORT ZafLanguageData : public ZafDataRecord
{
public:
	// --- General members ---
	ZafLanguageData(bool staticData = false);
	ZafLanguageData(ZafMessageStruct *data, bool staticData = false);
	ZafLanguageData(const ZafLanguageData &copy);
	virtual ~ZafLanguageData(void);

	// --- Locking ---
	void Lock(void);
	bool Locked(void);
	void UnLock(void);

	// --- Persistent members ---
	virtual ZafData *Duplicate(void);
#if defined(USE_ZAF_PERSISTENCE)
	ZafLanguageData(const ZafIChar *name, ZafDataPersistence &persist,
	 const ZafIChar *languageName = ZAF_NULLP(ZafIChar));
	static ZafElement *Read(const ZafIChar *name, ZafDataPersistence &persist);
	virtual void Write(ZafDataPersistence &persist);
#endif

	// --- Attributes & data access ---
	operator ZafMessageStruct *() { return (data); }
	// get
	ZafIChar *GetMessage(const ZafIChar *stringID, bool useDefault = false,
		ZafIChar *hotKeyChar = ZAF_NULLP(ZafIChar),
		int *hotKeyIndex = ZAF_NULLP(int)) const;
	ZafIChar *GetMessage(ZafNumberID numberID, bool useDefault = false,
		ZafIChar *hotKeyChar = ZAF_NULLP(ZafIChar),
		int *hotKeyIndex = ZAF_NULLP(int)) const;
	ZafMessageData *GetMessageData(const ZafIChar *stringID, bool useDefault = false);
	ZafMessageData *GetMessageData(ZafNumberID numberID, bool useDefault = false);
	int Messages(void);
	bool StaticData(void) const;
	// set
	virtual void Clear(void);
	virtual ZafError SetMessage(ZafNumberID numberID, ZafIChar *text,
		ZafIChar hotKeyChar = 0, int hotKeyIndex = -1);
	virtual ZafError SetMessages(ZafMessageStruct *value);
	virtual ZafError SetMessages(const ZafLanguageData &data);
	virtual bool SetStaticData(bool staticData);

	// --- List members ---
	ZafMessageData *Current(void) const { return ((ZafMessageData *)current); }
	ZafMessageData *First(void) const { return ((ZafMessageData *)first); }
	ZafMessageData *Last(void) const { return ((ZafMessageData *)last); }

	// --- Class identification ---
	static ZafClassID classID;
	static ZafClassNameChar ZAF_FARDATA className[];
	virtual ZafClassID ClassID(void) const { return (classID); }
	virtual ZafClassName ClassName(void) const { return (className); }
	virtual bool IsA(ZafClassID compareID) const;
	virtual bool IsA(ZafClassName compareName) const;

protected:
	int lockCount;
	bool staticData;
	ZafMessageStruct *data;

#if defined(USE_ZAF_PERSISTENCE)
	// --- Persistent members ---
	void ReadData(ZafDataPersistence &persist);
	virtual ZafDataConstructor ReadFunction(void) { return (ZafLanguageData::Read); }
	void WriteData(ZafDataPersistence &persist);
#endif
};


// --- inline functions ---
inline bool ZafLanguageData::StaticData(void) const { return (staticData); }

// --------------------------------------------------------------------------
// ----- ZafLanguageManager ----------------------------------------------------
// --------------------------------------------------------------------------

class ZAF_EXPORT ZafLanguageManager : public ZafDataRecord
{
public:
	static ZafIChar ZAF_FARDATA blankString[];
	static ZafIChar ZAF_FARDATA errorString[];

	// --- General members ---
	ZafLanguageManager(void);
	virtual ~ZafLanguageManager(void);

	// --- Data access ---
	static ZafLanguageData *Allocate(const ZafIChar *stringID,
		ZafMessageStruct *defaultData = ZAF_NULLP(ZafMessageStruct));
	static void Free(ZafLanguageData *messageGroup);

	// --- Language ---
	const ZafIChar *Language(void);
	ZafError SetLanguage(const ZafIChar *languageName);
	static const ZafIChar *LanguageName(void);
	static ZafError SetLanguageName(const ZafIChar *languageName);
	static void LanguageAllocate(const ZafIChar *name = ZAF_NULLP(ZafIChar));
	static void LanguageFree(bool globalRequest = false);

	// --- List members ---
	virtual ZafData *Add(ZafData *object, ZafData *position = ZAF_NULLP(ZafData));
	ZafLanguageData *Current(void) const { return((ZafLanguageData *)current); }
	ZafLanguageData *First(void) const { return((ZafLanguageData *)first); }
	ZafLanguageData *Last(void) const { return((ZafLanguageData *)last); }
	virtual ZafData *Subtract(ZafData *object);

	// --- Class identification ---
	static ZafClassID classID;
	static ZafClassNameChar ZAF_FARDATA className[];
	virtual ZafClassID ClassID(void) const { return (classID); }
	virtual ZafClassName ClassName(void) const { return (className); }
	virtual bool IsA(ZafClassID compareID) const;
	virtual bool IsA(ZafClassName compareName) const;

protected:
	ZafIChar *language;
};

extern ZAF_EXPORT ZafLanguageManager *zafLanguageManager;

#endif // Z_LANG_HPP

