
#ifndef __ttageditform_h__
#define __ttageditform_h__

#ifndef PandaWave_XFORM
#include <XForm.h>
#endif

#ifndef PandaWave_XPTRSET
#include <XPtrSet.h>
#endif

#ifndef __myth_defs_h__
#include "myth_defs.h"
#endif

#define TOGGLE_FLAG( num, flag ) ( def.flags = ( GetFlag(num) ) ? (def.flags|flag) : (def.flags&~flag) )

class XGCommandButton;
class XGStaticText;
class XGView;

class TTagEditForm: public XGForm {
	public:
							TTagEditForm( struct tag_entry *t );
		virtual				~TTagEditForm();
		
		virtual void		DoFormInitialize();
		
		virtual void		CommitToTag() = 0;
		virtual void		ReloadTag() = 0;
		virtual bool		NeedCommit() = 0;
		
		virtual void		FileChanged();
		
		virtual void		HandleTagChanged( tag group, tag id );
		
		DECLAREDISPATCH
		long					DoGetMenuStatus(long,void *);
		long					DoMenuCommand(long,void *);
		long					DoControlClick(long,void *);
		
		void					TagInfoChanged();
		
		bool					DoQueryDestroyWindow();
		
		// convenience accessors
		virtual void			SetInt( int view_id, int value );
		virtual void			SetFlag( int view_id, bool value );
		virtual void			SetFloat( int view_id, double value, int precision = 8 );
		virtual void			SetFixed( int view_id, fixed value );
		virtual void			SetFixedFraction( int view_id, fixed_fraction value );
		virtual void			SetPercentage( int view_id, fixed_fraction value );
		virtual void			SetShortFixed( int view_id, short_fixed value );
		virtual void			SetShortFixedFraction( int view_id, short_fixed_fraction value );
		virtual void			SetShortPercentage( int view_id, short_fixed_fraction value );
		virtual void			SetText( int view_id, const char *value );
		virtual void			SetTag( int view_id, tag type, tag value );
		virtual void			SetShortWorldDistance( int view_id, short_world_distance value );
		virtual void			SetWorldDistance( int view_id, world_distance value );
		virtual void			SetAngle( int view_id, int value );
		virtual void			SetAngleInSeconds( int view_id, int value );
		virtual void			SetColor( int view_id, const struct rgb_color &rgb );
		
		virtual int				GetInt( int view_id );
		virtual bool			GetFlag( int view_id );
		virtual double			GetFloat( int view_id );
		virtual fixed			GetFixed( int view_id );
		virtual fixed_fraction  GetFixedFraction( int view_id );
		virtual fixed_fraction	GetPercentage( int view_id );
		virtual short_fixed		GetShortFixed( int view_id );
		virtual short_fixed_fraction GetShortFixedFraction( int view_id );
		virtual short_fixed_fraction GetShortPercentage( int view_id );
		virtual void			GetText( int view_id, char *value, int maxlen );
		virtual tag				GetTag( int view_id );
		virtual short_world_distance GetShortWorldDistance( int view_id );
		virtual world_distance  GetWorldDistance( int view_id );
		virtual int				GetAngle( int view_id );
		virtual int				GetAngleInSeconds( int view_id );
		
		virtual void			SetEnabled( int view_id, bool enabled );
		virtual bool			IsEnabled( int view_id );
		
		virtual void			SetVisible( int view_id, bool visible );
		virtual bool			IsVisible( int view_id );
		
		virtual XGView *		GetView( int view_id );
		
		virtual	char			get_delta( char lower, char upper );
		virtual char			get_upper_bound( char lower, char delta );

		virtual unsigned char	get_delta( unsigned char lower, unsigned char upper );
		virtual unsigned char	get_upper_bound( unsigned char lower, unsigned char delta );

		virtual short			get_delta( short lower, short upper );
		virtual short			get_upper_bound( short lower, short delta );

		virtual unsigned short	get_delta( unsigned short lower, unsigned short upper );
		virtual unsigned short	get_upper_bound( unsigned short lower, unsigned short delta );

		virtual long			get_delta( long lower, long upper );
		virtual long			get_upper_bound( long lower, long delta );

		virtual unsigned long	get_delta( unsigned long lower, unsigned long upper );
		virtual unsigned long	get_upper_bound( unsigned long lower, unsigned long delta );

		virtual float			get_delta( float lower, float upper );
		virtual float			get_upper_bound( float lower, float delta );
		
	protected:
		tag_entry *				fEntry;
		
	private:
		XGCommandButton *		fFileBtn;
		XGCommandButton *		fReloadBtn;
		XGCommandButton *		fApplyBtn;
		XGStaticText *			fFilePath;
		
		static XGPtrSet<TTagEditForm> changeNotifyList;
		friend void				announce_tag_change( tag group, tag id );
};


#endif

