Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef TNZ_TEXTFIELD_INCLUDED
Toshihiro Shimizu 890ddd
#define TNZ_TEXTFIELD_INCLUDED
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tw/tw.h"
Toshihiro Shimizu 890ddd
#include "tw/textlistener.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#undef DVAPI
Toshihiro Shimizu 890ddd
#undef DVVAR
Toshihiro Shimizu 890ddd
#ifdef TWIN_EXPORTS
Toshihiro Shimizu 890ddd
#define DVAPI DV_EXPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_EXPORT_VAR
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#define DVAPI DV_IMPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_IMPORT_VAR
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef WIN32
Toshihiro Shimizu 890ddd
#pragma warning(push)
Toshihiro Shimizu 890ddd
#pragma warning(disable : 4251)
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DVAPI TTextField : public TWidget, public TTextListener
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	class Action
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	public:
Toshihiro Shimizu 890ddd
		virtual ~Action() {}
Toshihiro Shimizu 890ddd
		virtual void sendCommand(std::wstring) = 0;
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	class Listener
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	public:
Toshihiro Shimizu 890ddd
		virtual void onKeyPressed(int key){};
Toshihiro Shimizu 890ddd
		virtual void onFocusChange(bool on){};
Toshihiro Shimizu 890ddd
		virtual ~Listener() {}
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
protected:
Toshihiro Shimizu 890ddd
	std::wstring m_text, m_oldText;
Toshihiro Shimizu 890ddd
	int m_pos;
Toshihiro Shimizu 890ddd
	int m_sel0, m_sel1;
Toshihiro Shimizu 890ddd
	int m_off;
Toshihiro Shimizu 890ddd
	bool m_mouseDown;
Toshihiro Shimizu 890ddd
	int xToIndex(int x);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
	std::vector<action *=""> m_actions;</action>
Shinya Kitaoka 3bfa54
	std::vector<action *=""> m_commitActions;</action>
Toshihiro Shimizu 890ddd
	Listener *m_listener;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void updateOffset();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 3bfa54
	TTextField(TWidget *parent, std::string name = "textfield");
Toshihiro Shimizu 890ddd
	~TTextField();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	virtual void commit() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void draw();
Toshihiro Shimizu 890ddd
	void keyDown(int, TUINT32, const TPoint &);
Toshihiro Shimizu 890ddd
	void onDrop(std::wstring s);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void leftButtonDoubleClick(const TMouseEvent &e);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void leftButtonDown(const TMouseEvent &e);
Toshihiro Shimizu 890ddd
	void leftButtonDrag(const TMouseEvent &e);
Toshihiro Shimizu 890ddd
	void leftButtonUp(const TMouseEvent &e);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	std::wstring getText() const;
Toshihiro Shimizu 890ddd
	void setText(std::wstring s);
Toshihiro Shimizu 890ddd
	void setText(std::string s);
Toshihiro Shimizu 890ddd
	// NON invoca l'azione registrata
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void select(int s0, int s1);
Toshihiro Shimizu 890ddd
	void selectAll();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void addAction(Action *action);
Toshihiro Shimizu 890ddd
	void addCommitAction(Action *action);
Toshihiro Shimizu 890ddd
	void setListener(Listener *listener);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void onFocusChange(bool status);
Toshihiro Shimizu 890ddd
	FocusHandling getFocusHandling() const { return LISTEN_TO_FOCUS; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	virtual void pasteText(std::wstring text);
Toshihiro Shimizu 890ddd
	virtual std::wstring copyText();
Toshihiro Shimizu 890ddd
	virtual std::wstring cutText();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	virtual void drawFieldText(
Toshihiro Shimizu 890ddd
		const TPoint &origin,
Shinya Kitaoka 3bfa54
		std::wstring text);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef MACOSX
Toshihiro Shimizu 890ddd
	// pezza dovuta al baco del gcc3.3.1. Togliere quando lo si aggiorna al 3.3.2 o superiori
Toshihiro Shimizu 890ddd
	bool getCaret(TPoint &p, int &height);
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// toppa per aggiustare una bruttura grafica in Tab.
Toshihiro Shimizu 890ddd
	// va ripensata tutta la logica del posizionamento del
Toshihiro Shimizu 890ddd
	// testo
Toshihiro Shimizu 890ddd
	int m_dy;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	virtual void sendCommand();
Toshihiro Shimizu 890ddd
	virtual void sendCommitCommand();
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class t=""></class>
Toshihiro Shimizu 890ddd
class TTextFieldAction : public TTextField::Action
Toshihiro Shimizu 890ddd
{
Shinya Kitaoka 3bfa54
	typedef void (T::*Method)(std::wstring text);
Toshihiro Shimizu 890ddd
	T *m_target;
Toshihiro Shimizu 890ddd
	Method m_method;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	TTextFieldAction(T *target, Method method)
Toshihiro Shimizu 890ddd
		: m_target(target), m_method(method) {}
Shinya Kitaoka 3bfa54
	void sendCommand(std::wstring s) { (m_target->*m_method)(s); }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class t=""></class>
Shinya Kitaoka 3bfa54
void tconnect(TTextField *fld, T *target, void (T::*method)(std::wstring s))
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	fld->addCommitAction(new TTextFieldAction<t>(target, method));</t>
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DVAPI TNumField : public TTextField
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	class Event
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	public:
Toshihiro Shimizu 890ddd
		TNumField *m_field;
Toshihiro Shimizu 890ddd
		double m_value;
Toshihiro Shimizu 890ddd
		enum Reason { KeyPressed,
Toshihiro Shimizu 890ddd
					  FocusChange,
Toshihiro Shimizu 890ddd
					  ReturnPressed };
Toshihiro Shimizu 890ddd
		Reason m_reason;
Toshihiro Shimizu 890ddd
		Event(TNumField *field)
Toshihiro Shimizu 890ddd
			: m_field(field), m_value(field->getValue()), m_reason(KeyPressed)
Toshihiro Shimizu 890ddd
		{
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	class Action
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	public:
Toshihiro Shimizu 890ddd
		virtual ~Action() {}
Toshihiro Shimizu 890ddd
		virtual void sendCommand(const Event &ev) = 0;
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Toshihiro Shimizu 890ddd
	double m_minValue, m_maxValue;
Shinya Kitaoka 3bfa54
	std::vector<action *=""> m_numActions;</action>
Toshihiro Shimizu 890ddd
	bool m_isInteger;
Toshihiro Shimizu 890ddd
	int m_precision;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
protected:
Toshihiro Shimizu 890ddd
	double m_value;
Toshihiro Shimizu 890ddd
	virtual void valueToText();
Toshihiro Shimizu 890ddd
	virtual void textToValue();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void sendCommand();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 3bfa54
	TNumField(TWidget *parent, std::string name = "numfield");
Toshihiro Shimizu 890ddd
	~TNumField();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void keyDown(int, TUINT32, const TPoint &);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool getIsInteger() const { return m_isInteger; }
Toshihiro Shimizu 890ddd
	void setIsInteger(bool isInteger);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void setRange(double minValue, double maxValue);
Toshihiro Shimizu 890ddd
	void getRange(double &minValue, double &maxValue);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void setPrecision(int precision) { m_precision = precision; }
Toshihiro Shimizu 890ddd
	int getPrecision() { return m_precision; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double getValue() const { return m_value; }
Toshihiro Shimizu 890ddd
	void setValue(double value);
Toshihiro Shimizu 890ddd
	// NON invoca l'azione registrata
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void addAction(Action *action);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void onFocusChange(bool status);
Shinya Kitaoka 3bfa54
	void pasteText(std::wstring text);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class t=""></class>
Toshihiro Shimizu 890ddd
class TNumFieldAction : public TNumField::Action
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	T *m_target;
Toshihiro Shimizu 890ddd
	typedef void (T::*Method)(const TNumField::Event &e);
Toshihiro Shimizu 890ddd
	Method m_method;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	TNumFieldAction(T *target, Method method)
Toshihiro Shimizu 890ddd
		: m_target(target), m_method(method) {}
Toshihiro Shimizu 890ddd
	void sendCommand(const TNumField::Event &e) { (m_target->*m_method)(e); }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class t=""></class>
Toshihiro Shimizu 890ddd
void tconnect(TNumField *nf, T *target, void (T::*method)(const TNumField::Event &e))
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	nf->addAction(new TNumFieldAction<t>(target, method));</t>
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class TMeasuredValue;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DVAPI TMeasuredValueField : public TTextField
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	class Action
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	public:
Toshihiro Shimizu 890ddd
		virtual ~Action() {}
Toshihiro Shimizu 890ddd
		virtual void sendCommand(TMeasuredValueField *field) = 0;
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Toshihiro Shimizu 890ddd
	TMeasuredValue *m_value;
Shinya Kitaoka 3bfa54
	std::vector<action *=""> m_actions;</action>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 3bfa54
	TMeasuredValueField(TWidget *parent, std::string name = "numfield");
Toshihiro Shimizu 890ddd
	~TMeasuredValueField();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
	void setMeasure(std::string name);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TMeasuredValue *getMeasuredValue() const { return m_value; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void setValue(double v);
Toshihiro Shimizu 890ddd
	double getValue() const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void addAction(Action *action);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//void onFocusChange(bool status);
Toshihiro Shimizu 890ddd
	//void pasteText(wstring text);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void commit();
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class t=""></class>
Toshihiro Shimizu 890ddd
class TMeasuredValueFieldAction : public TMeasuredValueField::Action
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	typedef void (T::*Method)(TMeasuredValueField *fld);
Toshihiro Shimizu 890ddd
	T *m_target;
Toshihiro Shimizu 890ddd
	Method m_method;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	TMeasuredValueFieldAction(T *target, Method method)
Toshihiro Shimizu 890ddd
		: m_target(target), m_method(method) {}
Toshihiro Shimizu 890ddd
	void sendCommand(TMeasuredValueField *fld) { (m_target->*m_method)(fld); }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class t=""></class>
Toshihiro Shimizu 890ddd
void tconnect(TMeasuredValueField *fld, T *target, void (T::*method)(TMeasuredValueField *fld))
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	fld->addAction(new TMeasuredValueFieldAction<t>(target, method));</t>
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef WIN32
Toshihiro Shimizu 890ddd
#pragma warning(pop)
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif