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

77 lines
1.8 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_CHECKBOX_INCLUDED
#define TNZ_CHECKBOX_INCLUDED
//#include "tcommon.h"
#include "tw/tw.h"
#include "tw/action.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
class TCheckBoxActionInterface;
2016-06-15 18:43:10 +12:00
class DVAPI TCheckBox : public TWidget {
class TCheckBoxData;
TCheckBoxData *m_data;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TCheckBox(TWidget *parent, string name = "button");
~TCheckBox();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void repaint();
void leftButtonDown(const TMouseEvent &);
void leftButtonUp(const TMouseEvent &);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
bool isSelected() const;
void addAction(TCheckBoxActionInterface *);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void select(bool on);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
bool isGray() const;
void setIsGray(bool on);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// per default switchOff e' abilitato. se disabilitato il checkbox si puo'
// spegnare solo con select(false) (e non con il mouse). Questo serve
// per implementare un gruppo di radio button (in cui si puo' fare click
// solo su quelli spenti)
void enableSwitchOff(bool enabled);
2016-03-19 06:57:51 +13:00
};
2016-06-15 18:43:10 +12:00
class DVAPI TCheckBoxActionInterface {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TCheckBoxActionInterface() {}
virtual ~TCheckBoxActionInterface() {}
virtual void triggerAction(TCheckBox *checkbox, bool selected) = 0;
2016-03-19 06:57:51 +13:00
};
template <class T>
2016-06-15 18:43:10 +12:00
class TCheckBoxAction : public TCheckBoxActionInterface {
typedef void (T::*Method)(TCheckBox *checkbox, bool selected);
T *m_target;
Method m_method;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TCheckBoxAction(T *target, Method method)
: m_target(target), m_method(method) {}
void triggerAction(TCheckBox *checkbox, bool selected) {
(m_target->*m_method)(checkbox, selected);
}
2016-03-19 06:57:51 +13:00
};
template <class T>
2016-06-15 18:43:10 +12:00
inline void tconnect(TCheckBox &src, T *target,
void (T::*method)(TCheckBox *checkbox, bool selected)) {
src.addAction(new TCheckBoxAction<T>(target, method));
2016-03-19 06:57:51 +13:00
}
#endif