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

88 lines
1.9 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_COMBOBOX_INCLUDED
#define TNZ_COMBOBOX_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 TTextField;
class TComboMenu;
class TComboBoxActionInterface;
//-------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
class DVAPI TComboBox : public TWidget {
TTextField *m_textField;
TComboMenu *m_menu;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
vector<pair<string, string>> *m_options;
vector<TComboBoxActionInterface *> *m_actions;
void sendCommand();
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TComboBox(TWidget *parent, string name = "combobox");
~TComboBox();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void draw();
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
void leftButtonDrag(const TPoint &pos, UCHAR pressure);
2016-03-19 06:57:51 +13:00
*/
2016-06-15 18:43:10 +12:00
TPoint getHotSpot() const;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
string getText() const;
void setText(string s);
void addOption(string s, string help);
void deleteOptions();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void addAction(TComboBoxActionInterface *action);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
friend class TComboMenu;
// int getOptionsCount() const;
// string getOption(int index) const;
2016-03-19 06:57:51 +13:00
};
2016-06-15 18:43:10 +12:00
class DVAPI TComboBoxActionInterface {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TComboBoxActionInterface() {}
virtual ~TComboBoxActionInterface() {}
virtual void triggerAction(TComboBox *cb, string text) = 0;
2016-03-19 06:57:51 +13:00
};
template <class T>
2016-06-15 18:43:10 +12:00
class TComboBoxAction : public TComboBoxActionInterface {
typedef void (T::*Method)(TComboBox *vf, string text);
T *m_target;
Method m_method;
2016-03-19 06:57:51 +13:00
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) {
(m_target->*m_method)(vf, text);
}
2016-03-19 06:57:51 +13:00
};
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)) {
src.addAction(new TComboBoxAction<T>(target, method));
2016-03-19 06:57:51 +13:00
}
#endif