Shinya Kitaoka 810553
#pragma once
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef TNZ_OPTIONMENU_INCLUDED
Toshihiro Shimizu 890ddd
#define TNZ_OPTIONMENU_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
Toshihiro Shimizu 890ddd
class TPopupMenu;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef WIN32
Toshihiro Shimizu 890ddd
#pragma warning(disable : 4251)
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class DVAPI TGenericOptionMenuAction {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  virtual ~TGenericOptionMenuAction() {}
Shinya Kitaoka 120a6e
  virtual void sendCommand(string item) = 0;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class DVAPI TGenericOptionMenuWAction {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  virtual ~TGenericOptionMenuWAction() {}
Shinya Kitaoka 120a6e
  virtual void sendCommand(wstring item) = 0;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class t=""></class>
Shinya Kitaoka 120a6e
class TOptionMenuAction : public TGenericOptionMenuAction {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  typedef void (T::*Method)(string item);
Shinya Kitaoka 120a6e
  TOptionMenuAction(T *target, Method method)
Shinya Kitaoka 120a6e
      : m_target(target), m_method(method) {}
Shinya Kitaoka 120a6e
  void sendCommand(string item) { (m_target->*m_method)(item); }
Shinya Kitaoka 120a6e
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  T *m_target;
Shinya Kitaoka 120a6e
  Method m_method;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
template <class t=""></class>
Shinya Kitaoka 120a6e
class TOptionMenuActionW : public TGenericOptionMenuWAction {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  typedef void (T::*Method)(wstring item);
Shinya Kitaoka 120a6e
  TOptionMenuActionW(T *target, Method method)
Shinya Kitaoka 120a6e
      : m_target(target), m_method(method) {}
Shinya Kitaoka 120a6e
  void sendCommand(wstring item) { (m_target->*m_method)(item); }
Shinya Kitaoka 120a6e
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  T *m_target;
Shinya Kitaoka 120a6e
  Method m_method;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class DVAPI TOptionMenu : public TWidget {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TOptionMenu(TWidget *parent, string name = "optionMenu");
Shinya Kitaoka 120a6e
  ~TOptionMenu();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void setAction(TGenericOptionMenuAction *action) { m_action = action; }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void repaint();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void configureNotify(const TDimension &size);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void leftButtonDown(const TMouseEvent &);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  string getText() const;
Shinya Kitaoka 120a6e
  void setText(string s);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void setLabel(wstring title);
Shinya Kitaoka 120a6e
  void setLabelWidth(int lx);
Shinya Kitaoka 120a6e
  wstring getLabel() const { return m_label; }
Shinya Kitaoka 120a6e
  int getLabelWidth() const { return m_labelWidth; }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bool isOption(string s) const;
Shinya Kitaoka 120a6e
  void addOption(string cmdName);
Shinya Kitaoka 120a6e
  void addOption(string cmdName, wstring title);
Shinya Kitaoka 120a6e
  void deleteOption(string s);
Shinya Kitaoka 120a6e
  void deleteAllOptions();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  TPopupMenu *m_menu;
Shinya Kitaoka 120a6e
  string m_currentOption;
Shinya Kitaoka 120a6e
  wstring m_currentOptionTitle;
Shinya Kitaoka 120a6e
  wstring m_label;
Shinya Kitaoka 120a6e
  int m_labelWidth;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  typedef std::vector<std::pair<string, wstring="">> OptionList;</std::pair<string,>
Shinya Kitaoka 120a6e
  OptionList m_options;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TGenericOptionMenuAction *m_action;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class t=""></class>
Shinya Kitaoka 120a6e
class TOptionMenuWAction : public TGenericOptionMenuWAction {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  typedef void (T::*Method)(wstring item);
Shinya Kitaoka 120a6e
  TOptionMenuWAction(T *target, Method method)
Shinya Kitaoka 120a6e
      : m_target(target), m_method(method) {}
Shinya Kitaoka 120a6e
  void sendCommand(wstring item) { (m_target->*m_method)(item); }
Shinya Kitaoka 120a6e
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  T *m_target;
Shinya Kitaoka 120a6e
  Method m_method;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class DVAPI TOptionMenuW : public TWidget {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TOptionMenuW(TWidget *parent, string name = "optionMenu");
Shinya Kitaoka 120a6e
  ~TOptionMenuW();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void setAction(TGenericOptionMenuWAction *action) { m_action = action; }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void repaint();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void configureNotify(const TDimension &size);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void leftButtonDown(const TMouseEvent &);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  wstring getText() const;
Shinya Kitaoka 120a6e
  void setText(wstring s);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void setLabel(wstring label);
Shinya Kitaoka 120a6e
  void setLabelWidth(int width);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bool isOption(wstring s) const;
Shinya Kitaoka 120a6e
  void addOption(wstring item);
Shinya Kitaoka 120a6e
  void deleteOption(wstring s);
Shinya Kitaoka 120a6e
  void deleteAllOptions();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  typedef std::vector<wstring> OptionList;</wstring>
Shinya Kitaoka 120a6e
  const OptionList getOptions() const { return m_options; };
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  TPopupMenu *m_menu;
Shinya Kitaoka 120a6e
  wstring m_currentOption;
Shinya Kitaoka 120a6e
  wstring m_label;
Shinya Kitaoka 120a6e
  int m_labelWidth;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  OptionList m_options;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TGenericOptionMenuWAction *m_action;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*
Toshihiro Shimizu 890ddd
class DVAPI TComboBoxActionInterface {
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
  TComboBoxActionInterface() {}
Toshihiro Shimizu 890ddd
  virtual ~TComboBoxActionInterface() {}
Toshihiro Shimizu 890ddd
  virtual void triggerAction(TComboBox*cb, string text) = 0;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class t=""></class>
Toshihiro Shimizu 890ddd
class TComboBoxAction : public TComboBoxActionInterface {
Toshihiro Shimizu 890ddd
  typedef void (T::*Method)(TComboBox *vf, string text);
Toshihiro Shimizu 890ddd
  T *m_target;
Toshihiro Shimizu 890ddd
  Method m_method;
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TComboBoxAction(T*target, Method method) : m_target(target), m_method(method)
Shinya Kitaoka 120a6e
{}
Shinya Kitaoka 120a6e
  void triggerAction(TComboBox*vf, string text)
Toshihiro Shimizu 890ddd
    {(m_target->*m_method)(vf, text); }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class t=""></class>
Shinya Kitaoka 120a6e
inline void tconnect(TComboBox&src, T *target, void (T::*method)(TComboBox *vf,
Shinya Kitaoka 120a6e
string text))
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
  src.addAction(new TComboBoxAction<t>(target, method));</t>
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class t=""></class>
Shinya Kitaoka 120a6e
void tconnect(TOptionMenu &menu, T *target, void (T::*method)(string)) {
Shinya Kitaoka 120a6e
  menu.setAction(new TOptionMenuAction<t>(target, method));</t>
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class t=""></class>
Shinya Kitaoka 120a6e
void tconnect(TOptionMenuW &menu, T *target, void (T::*method)(wstring)) {
Shinya Kitaoka 120a6e
  menu.setAction(new TOptionMenuActionW<t>(target, method));</t>
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif