tahoma2d/toonz/sources/include/tw/optionmenu.h

216 lines
5.2 KiB
C
Raw Normal View History

2016-05-17 03:04:11 +12:00
#pragma once
2016-03-19 06:57:51 +13:00
#ifndef TNZ_OPTIONMENU_INCLUDED
#define TNZ_OPTIONMENU_INCLUDED
#include "tw/tw.h"
#undef DVAPI
#undef DVVAR
#ifdef TWIN_EXPORTS
#define DVAPI DV_EXPORT_API
#define DVVAR DV_EXPORT_VAR
#else
#define DVAPI DV_IMPORT_API
#define DVVAR DV_IMPORT_VAR
#endif
// forward declaration
class TPopupMenu;
#ifdef WIN32
#pragma warning(disable : 4251)
#endif
//-------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
class DVAPI TGenericOptionMenuAction {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
virtual ~TGenericOptionMenuAction() {}
virtual void sendCommand(string item) = 0;
2016-03-19 06:57:51 +13:00
};
2016-06-15 18:43:10 +12:00
class DVAPI TGenericOptionMenuWAction {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
virtual ~TGenericOptionMenuWAction() {}
virtual void sendCommand(wstring item) = 0;
2016-03-19 06:57:51 +13:00
};
//-------------------------------------------------------------------
template <class T>
2016-06-15 18:43:10 +12:00
class TOptionMenuAction : public TGenericOptionMenuAction {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
typedef void (T::*Method)(string item);
TOptionMenuAction(T *target, Method method)
: m_target(target), m_method(method) {}
void sendCommand(string item) { (m_target->*m_method)(item); }
2016-03-19 06:57:51 +13:00
private:
2016-06-15 18:43:10 +12:00
T *m_target;
Method m_method;
2016-03-19 06:57:51 +13:00
};
//-------------------------------------------------------------------
template <class T>
2016-06-15 18:43:10 +12:00
class TOptionMenuActionW : public TGenericOptionMenuWAction {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
typedef void (T::*Method)(wstring item);
TOptionMenuActionW(T *target, Method method)
: m_target(target), m_method(method) {}
void sendCommand(wstring item) { (m_target->*m_method)(item); }
2016-03-19 06:57:51 +13:00
private:
2016-06-15 18:43:10 +12:00
T *m_target;
Method m_method;
2016-03-19 06:57:51 +13:00
};
//-------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
class DVAPI TOptionMenu : public TWidget {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TOptionMenu(TWidget *parent, string name = "optionMenu");
~TOptionMenu();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setAction(TGenericOptionMenuAction *action) { m_action = action; }
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void repaint();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void configureNotify(const TDimension &size);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void leftButtonDown(const TMouseEvent &);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
string getText() const;
void setText(string s);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setLabel(wstring title);
void setLabelWidth(int lx);
wstring getLabel() const { return m_label; }
int getLabelWidth() const { return m_labelWidth; }
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
bool isOption(string s) const;
void addOption(string cmdName);
void addOption(string cmdName, wstring title);
void deleteOption(string s);
void deleteAllOptions();
2016-03-19 06:57:51 +13:00
private:
2016-06-15 18:43:10 +12:00
TPopupMenu *m_menu;
string m_currentOption;
wstring m_currentOptionTitle;
wstring m_label;
int m_labelWidth;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
typedef std::vector<std::pair<string, wstring>> OptionList;
OptionList m_options;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TGenericOptionMenuAction *m_action;
2016-03-19 06:57:51 +13:00
};
//-------------------------------------------------------------------
template <class T>
2016-06-15 18:43:10 +12:00
class TOptionMenuWAction : public TGenericOptionMenuWAction {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
typedef void (T::*Method)(wstring item);
TOptionMenuWAction(T *target, Method method)
: m_target(target), m_method(method) {}
void sendCommand(wstring item) { (m_target->*m_method)(item); }
2016-03-19 06:57:51 +13:00
private:
2016-06-15 18:43:10 +12:00
T *m_target;
Method m_method;
2016-03-19 06:57:51 +13:00
};
//-------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
class DVAPI TOptionMenuW : public TWidget {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TOptionMenuW(TWidget *parent, string name = "optionMenu");
~TOptionMenuW();
void setAction(TGenericOptionMenuWAction *action) { m_action = action; }
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void repaint();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void configureNotify(const TDimension &size);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void leftButtonDown(const TMouseEvent &);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
wstring getText() const;
void setText(wstring s);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setLabel(wstring label);
void setLabelWidth(int width);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
bool isOption(wstring s) const;
void addOption(wstring item);
void deleteOption(wstring s);
void deleteAllOptions();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
typedef std::vector<wstring> OptionList;
const OptionList getOptions() const { return m_options; };
2016-03-19 06:57:51 +13:00
private:
2016-06-15 18:43:10 +12:00
TPopupMenu *m_menu;
wstring m_currentOption;
wstring m_label;
int m_labelWidth;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
OptionList m_options;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TGenericOptionMenuWAction *m_action;
2016-03-19 06:57:51 +13:00
};
//-------------------------------------------------------------------
/*
class DVAPI TComboBoxActionInterface {
public:
TComboBoxActionInterface() {}
virtual ~TComboBoxActionInterface() {}
virtual void triggerAction(TComboBox*cb, string text) = 0;
};
//-------------------------------------------------------------------
template <class T>
class TComboBoxAction : public TComboBoxActionInterface {
typedef void (T::*Method)(TComboBox *vf, string text);
T *m_target;
Method m_method;
public:
2016-06-15 18:43:10 +12:00
TComboBoxAction(T*target, Method method) : m_target(target), m_method(method)
{}
void triggerAction(TComboBox*vf, string text)
2016-03-19 06:57:51 +13:00
{(m_target->*m_method)(vf, text); }
};
//-------------------------------------------------------------------
template <class T>
2016-06-15 18:43:10 +12:00
inline void tconnect(TComboBox&src, T *target, void (T::*method)(TComboBox *vf,
string text))
2016-03-19 06:57:51 +13:00
{
src.addAction(new TComboBoxAction<T>(target, method));
}
*/
//-------------------------------------------------------------------
template <class T>
2016-06-15 18:43:10 +12:00
void tconnect(TOptionMenu &menu, T *target, void (T::*method)(string)) {
menu.setAction(new TOptionMenuAction<T>(target, method));
2016-03-19 06:57:51 +13:00
}
//-------------------------------------------------------------------
template <class T>
2016-06-15 18:43:10 +12:00
void tconnect(TOptionMenuW &menu, T *target, void (T::*method)(wstring)) {
menu.setAction(new TOptionMenuActionW<T>(target, method));
2016-03-19 06:57:51 +13:00
}
#endif