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

108 lines
2.5 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 TEXTLIST_INCLUDED
#define TEXTLIST_INCLUDED
#include "tw/tw.h"
#include "tw/scrollview.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
#ifdef WIN32
#pragma warning(disable : 4251)
#endif
//-------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
class DVAPI TGenericTextListAction {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
virtual ~TGenericTextListAction() {}
virtual void sendCommand(int itemIndex) = 0;
2016-03-19 06:57:51 +13:00
};
//-------------------------------------------------------------------
template <class T>
2016-06-15 18:43:10 +12:00
class TTextListAction : public TGenericTextListAction {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
typedef void (T::*Method)(int itemIndex);
TTextListAction(T *target, Method method)
: m_target(target), m_method(method) {}
void sendCommand(int itemIndex) { (m_target->*m_method)(itemIndex); }
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 TTextListItem {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TTextListItem(const std::string &id, const std::string &caption);
virtual ~TTextListItem() {}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
std::string getId() { return m_id; }
std::string getCaption() { return m_caption; }
2016-03-19 06:57:51 +13:00
private:
2016-06-15 18:43:10 +12:00
std::string m_id;
std::string m_caption;
2016-03-19 06:57:51 +13:00
};
//-------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
class DVAPI TTextList : public TWidget {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TTextList(TWidget *parent, std::string name = "textlist");
~TTextList();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void addItem(TTextListItem *item);
void removeItem(const std::string &itemId);
void clearAll();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
int getItemCount() const;
TTextListItem *getItem(int i) const;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// returns the index of item, -1 if not present
int itemToIndex(const std::string &itemId);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
int getSelectedItemCount() const;
TTextListItem *getSelectedItem(int i) const;
std::string getSelectedItemId(
int i) const; // returns the id of the i-th item selected
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void select(int i, bool on);
void select(const std::string &itemId, bool on);
void unselectAll();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
bool isSelected(int i) const;
bool isSelected(const std::string &itemId) const;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setSelAction(TGenericTextListAction *action);
void setDblClickAction(TGenericTextListAction *action);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void draw();
void configureNotify(const TDimension &d);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void leftButtonDown(const TMouseEvent &e);
void leftButtonDoubleClick(const TMouseEvent &e);
void keyDown(int key, unsigned long mod, const TPoint &);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void scrollTo(int y);
2016-03-19 06:57:51 +13:00
private:
2016-06-15 18:43:10 +12:00
class Data;
Data *m_data;
2016-03-19 06:57:51 +13:00
};
#endif