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