tahoma2d/toonz/sources/toonzfarm/tfarmclient/textlist.h

94 lines
2.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 TEXTLIST_INCLUDED
#define TEXTLIST_INCLUDED
#include "tw/tw.h"
#include "tw/scrollview.h"
//-------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
class 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 TTextListItem {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TTextListItem(const string &id, const string &caption);
virtual ~TTextListItem() {}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
string getId() { return m_id; }
string getCaption() { return m_caption; }
2016-03-19 06:57:51 +13:00
private:
2016-06-15 18:43:10 +12:00
string m_id;
string m_caption;
2016-03-19 06:57:51 +13:00
};
//-------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
class TTextList : public TWidget {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TTextList(TWidget *parent, 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 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 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;
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 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 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