Shinya Kitaoka 810553
#pragma once
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef TNZ_COMBOBOX_INCLUDED
Toshihiro Shimizu 890ddd
#define TNZ_COMBOBOX_INCLUDED
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tw/tw.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
// forward declaration
Toshihiro Shimizu 890ddd
class TTextField;
Toshihiro Shimizu 890ddd
class TComboMenu;
Toshihiro Shimizu 890ddd
class TComboBoxActionInterface;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class DVAPI TComboBox : public TWidget {
Shinya Kitaoka 120a6e
  TTextField *m_textField;
Shinya Kitaoka 120a6e
  TComboMenu *m_menu;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  vector<pair<string, string="">> *m_options;</pair<string,>
Shinya Kitaoka 120a6e
  vector<tcomboboxactioninterface *=""> *m_actions;</tcomboboxactioninterface>
Shinya Kitaoka 120a6e
  void sendCommand();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TComboBox(TWidget *parent, string name = "combobox");
Shinya Kitaoka 120a6e
  ~TComboBox();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void draw();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void configureNotify(const TDimension &size);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void leftButtonDown(const TMouseEvent &);
Shinya Kitaoka 120a6e
  /*
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void leftButtonDrag(const TPoint &pos, UCHAR pressure);
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
  TPoint getHotSpot() const;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  string getText() const;
Shinya Kitaoka 120a6e
  void setText(string s);
Shinya Kitaoka 120a6e
  void addOption(string s, string help);
Shinya Kitaoka 120a6e
  void deleteOptions();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void addAction(TComboBoxActionInterface *action);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  friend class TComboMenu;
Shinya Kitaoka 120a6e
  //	int getOptionsCount() const;
Shinya Kitaoka 120a6e
  //  string getOption(int index) const;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class DVAPI TComboBoxActionInterface {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TComboBoxActionInterface() {}
Shinya Kitaoka 120a6e
  virtual ~TComboBoxActionInterface() {}
Shinya Kitaoka 120a6e
  virtual void triggerAction(TComboBox *cb, string text) = 0;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class t=""></class>
Shinya Kitaoka 120a6e
class TComboBoxAction : public TComboBoxActionInterface {
Shinya Kitaoka 120a6e
  typedef void (T::*Method)(TComboBox *vf, string text);
Shinya Kitaoka 120a6e
  T *m_target;
Shinya Kitaoka 120a6e
  Method m_method;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TComboBoxAction(T *target, Method method)
Shinya Kitaoka 120a6e
      : m_target(target), m_method(method) {}
Shinya Kitaoka 120a6e
  void triggerAction(TComboBox *vf, string text) {
Shinya Kitaoka 120a6e
    (m_target->*m_method)(vf, text);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class t=""></class>
Shinya Kitaoka 120a6e
inline void tconnect(TComboBox &src, T *target,
Shinya Kitaoka 120a6e
                     void (T::*method)(TComboBox *vf, string text)) {
Shinya Kitaoka 120a6e
  src.addAction(new TComboBoxAction<t>(target, method));</t>
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif