|
Shinya Kitaoka |
810553 |
#pragma once
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifndef TNZ_TREEVIEW_INCLUDED
|
|
Toshihiro Shimizu |
890ddd |
#define TNZ_TREEVIEW_INCLUDED
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "tw/tw.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tw/dragdrop.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include <set></set>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#undef DVAPI
|
|
Toshihiro Shimizu |
890ddd |
#undef DVVAR
|
|
Toshihiro Shimizu |
890ddd |
#ifdef TWIN_EXPORTS
|
|
Toshihiro Shimizu |
890ddd |
#define DVAPI DV_EXPORT_API
|
|
Toshihiro Shimizu |
890ddd |
#define DVVAR DV_EXPORT_VAR
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
#define DVAPI DV_IMPORT_API
|
|
Toshihiro Shimizu |
890ddd |
#define DVVAR DV_IMPORT_VAR
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef WIN32
|
|
Toshihiro Shimizu |
890ddd |
#pragma warning(disable : 4251)
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class TTreeView;
|
|
Toshihiro Shimizu |
890ddd |
class TTreeViewItem;
|
|
Toshihiro Shimizu |
890ddd |
class TTreeViewItemParent;
|
|
Toshihiro Shimizu |
890ddd |
class TScrollbar;
|
|
Toshihiro Shimizu |
890ddd |
class TTextField;
|
|
Toshihiro Shimizu |
890ddd |
class TContextMenu;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
class DVAPI TTreeViewItemUpdater {
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
virtual bool done() const = 0;
|
|
Shinya Kitaoka |
120a6e |
virtual void next() = 0;
|
|
Shinya Kitaoka |
120a6e |
virtual bool matchItem(const TTreeViewItem *) const = 0;
|
|
Shinya Kitaoka |
120a6e |
virtual TTreeViewItem *createItem(TTreeViewItemParent *parent) const = 0;
|
|
Shinya Kitaoka |
120a6e |
virtual ~TTreeViewItemUpdater() {}
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
class DVAPI TTreeViewItemParent {
|
|
Shinya Kitaoka |
120a6e |
TTreeView *m_treeView;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
protected:
|
|
Shinya Kitaoka |
120a6e |
bool m_valid;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
typedef vector<ttreeviewitem *=""> ItemContainer;</ttreeviewitem>
|
|
Shinya Kitaoka |
120a6e |
ItemContainer m_children;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
TTreeViewItemParent() : m_treeView(0), m_valid(true) {}
|
|
Shinya Kitaoka |
120a6e |
virtual ~TTreeViewItemParent();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void clearItems();
|
|
Shinya Kitaoka |
120a6e |
int getItemCount() const;
|
|
Shinya Kitaoka |
120a6e |
TTreeViewItem *getItem(int index) const;
|
|
Shinya Kitaoka |
120a6e |
TTreeViewItem *getItem(wstring name) const;
|
|
Shinya Kitaoka |
120a6e |
TTreeViewItem *getItem(string name) const;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void addItem(TTreeViewItem *item);
|
|
Shinya Kitaoka |
120a6e |
void removeItem(TTreeViewItem *item);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void updateItems(TTreeViewItemUpdater &updater);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
bool hasChild(TTreeViewItem *item) const;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
virtual void onItemChange();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void setTreeView(TTreeView *treeView) { m_treeView = treeView; }
|
|
Shinya Kitaoka |
120a6e |
TTreeView *getTreeView() const { return m_treeView; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
private:
|
|
Shinya Kitaoka |
120a6e |
// not implemented
|
|
Shinya Kitaoka |
120a6e |
TTreeViewItemParent(const TTreeViewItemParent &);
|
|
Shinya Kitaoka |
120a6e |
TTreeViewItemParent &operator=(const TTreeViewItemParent &);
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
class DVAPI TTreeViewItem : public TTreeViewItemParent {
|
|
Shinya Kitaoka |
120a6e |
unsigned char m_status;
|
|
Shinya Kitaoka |
120a6e |
TTreeViewItemParent *m_parent;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
TTreeViewItem(TTreeViewItemParent *parent);
|
|
Shinya Kitaoka |
120a6e |
virtual ~TTreeViewItem();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TTreeViewItemParent *getParent() const { return m_parent; }
|
|
Shinya Kitaoka |
120a6e |
void setParent(TTreeViewItemParent *parent);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void clearParent() { m_parent = 0; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
virtual void onOpen() {}
|
|
Shinya Kitaoka |
120a6e |
virtual void onClose() {}
|
|
Shinya Kitaoka |
120a6e |
virtual void onDoubleClick();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
virtual TTreeViewItem *getSon(string sonName) { return 0; }
|
|
Shinya Kitaoka |
120a6e |
virtual TTreeViewItem *getSon(wstring sonName) { return 0; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
bool isLeaf() const;
|
|
Shinya Kitaoka |
120a6e |
bool isEmpty() const;
|
|
Shinya Kitaoka |
120a6e |
bool isOpen() const;
|
|
Shinya Kitaoka |
120a6e |
bool isSelected() const;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void open();
|
|
Shinya Kitaoka |
120a6e |
void close();
|
|
Shinya Kitaoka |
120a6e |
virtual void refresh();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void setIsLeaf(bool isLeaf);
|
|
Shinya Kitaoka |
120a6e |
void select(bool on);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
bool unselectDescendents(); // ritorna true se ce n'era uno selezionato
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// "origin" sono le coordinate del punto in basso a sinistra dell'icona
|
|
Shinya Kitaoka |
120a6e |
virtual void drawIcon(TTreeView *w, const TPoint &origin);
|
|
Shinya Kitaoka |
120a6e |
virtual void drawName(TTreeView *w, const TPoint &origin);
|
|
Shinya Kitaoka |
120a6e |
virtual void draw(TTreeView *w, const TPoint &origin);
|
|
Shinya Kitaoka |
120a6e |
virtual int getWidth(TTreeView *w);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
virtual wstring getName() const { return L"noname"; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
virtual TDimension getIconSize() const;
|
|
Shinya Kitaoka |
120a6e |
virtual wstring getTooltipString() { return wstring(); }
|
|
Shinya Kitaoka |
120a6e |
virtual string getContextHelpReference() { return string(); }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
virtual bool isRenameEnabled() const { return false; }
|
|
Shinya Kitaoka |
120a6e |
virtual void rename(wstring name){};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
virtual TContextMenu *createContextMenu() { return 0; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
virtual bool acceptDrop(const TData *data) const { return false; }
|
|
Shinya Kitaoka |
120a6e |
virtual bool drop(const TData *data) { return false; }
|
|
Shinya Kitaoka |
120a6e |
virtual bool click(const TPoint &p) { return false; }
|
|
Shinya Kitaoka |
120a6e |
virtual bool drag(const TPoint &p) { return false; }
|
|
Shinya Kitaoka |
120a6e |
virtual bool rightClick(const TPoint &p);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
private:
|
|
Shinya Kitaoka |
120a6e |
// not implemented
|
|
Shinya Kitaoka |
120a6e |
TTreeViewItem(const TTreeViewItem &);
|
|
Shinya Kitaoka |
120a6e |
TTreeViewItem &operator=(const TTreeViewItem &);
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
class DVAPI TTreeView : public TWidget,
|
|
Shinya Kitaoka |
120a6e |
public TTreeViewItemParent,
|
|
Shinya Kitaoka |
120a6e |
public TDragDropListener {
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
class Listener {
|
|
Shinya Kitaoka |
120a6e |
public:
|
|
Shinya Kitaoka |
120a6e |
virtual void onTreeViewSelect(TTreeView *treeView) = 0;
|
|
Shinya Kitaoka |
120a6e |
virtual ~Listener() {}
|
|
Shinya Kitaoka |
120a6e |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
protected:
|
|
Shinya Kitaoka |
120a6e |
struct VisibleItem {
|
|
Shinya Kitaoka |
120a6e |
TPoint m_pos;
|
|
Shinya Kitaoka |
120a6e |
// m_pos e' la coordinata del punto in basso a sinistra dell'icona
|
|
Shinya Kitaoka |
120a6e |
// (l'origine e' il punto in alto a sinistra della prima icona)
|
|
Shinya Kitaoka |
120a6e |
int m_height;
|
|
Shinya Kitaoka |
120a6e |
// m_height == getIconSize().ly
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TTreeViewItem *m_item;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
enum { LastSiblingFlag = 0x1, RootFlag = 0x2, SonFlag = 0x4 };
|
|
Shinya Kitaoka |
120a6e |
int m_status;
|
|
Shinya Kitaoka |
120a6e |
// int m_siblingLinkLength;
|
|
Shinya Kitaoka |
120a6e |
// int m_childLinkLength;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
VisibleItem();
|
|
Shinya Kitaoka |
120a6e |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int m_xMargin, m_yMargin,
|
|
Shinya Kitaoka |
120a6e |
m_iconMargin; // distanza orizzontale fra il bottone "+/-" e l'icona
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
vector<visibleitem> m_visibleItems;</visibleitem>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifndef MACOSX
|
|
Shinya Kitaoka |
120a6e |
// togliere l'ifdef con il gcc3.3.2
|
|
Shinya Kitaoka |
120a6e |
bool m_valid;
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Shinya Kitaoka |
120a6e |
int m_height;
|
|
Shinya Kitaoka |
120a6e |
int m_yoffset;
|
|
Shinya Kitaoka |
120a6e |
int m_xoffset;
|
|
Shinya Kitaoka |
120a6e |
// int m_selectedItemIndex;
|
|
Shinya Kitaoka |
120a6e |
std::set<int> m_selectedItemIndices;</int>
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TScrollbar *m_vScb, *m_hScb;
|
|
Shinya Kitaoka |
120a6e |
TTextField *m_renameTextField;
|
|
Shinya Kitaoka |
120a6e |
bool m_multiSelectionEnabled;
|
|
Shinya Kitaoka |
120a6e |
int m_dropIndex;
|
|
Shinya Kitaoka |
120a6e |
vector<listener *=""> m_listeners;</listener>
|
|
Shinya Kitaoka |
120a6e |
TPoint m_lastMousePos;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
// costruttore/distruttore
|
|
Shinya Kitaoka |
120a6e |
TTreeView(TWidget *parent, string name = "treeView");
|
|
Shinya Kitaoka |
120a6e |
~TTreeView();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// listeners
|
|
Shinya Kitaoka |
120a6e |
void addListener(Listener *listener);
|
|
Shinya Kitaoka |
120a6e |
void removeListener(Listener *listener);
|
|
Shinya Kitaoka |
120a6e |
void notifyListeners();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// configure
|
|
Shinya Kitaoka |
120a6e |
void setScrollbars(TScrollbar *h, TScrollbar *v);
|
|
Shinya Kitaoka |
120a6e |
void enableMultiSelection(bool on);
|
|
Shinya Kitaoka |
120a6e |
bool isMultiSelectionEnabled() const { return m_multiSelectionEnabled; }
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// resize
|
|
Shinya Kitaoka |
120a6e |
void configureNotify(const TDimension &s);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// draw
|
|
Shinya Kitaoka |
120a6e |
void repaint();
|
|
Shinya Kitaoka |
120a6e |
virtual void drawButton(const TPoint &p, bool open);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// event handlers
|
|
Shinya Kitaoka |
120a6e |
void leftButtonDown(const TMouseEvent &e);
|
|
Shinya Kitaoka |
120a6e |
void leftButtonDrag(const TMouseEvent &e);
|
|
Shinya Kitaoka |
120a6e |
void leftButtonUp(const TMouseEvent &e);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void rightButtonDown(const TMouseEvent &e);
|
|
Shinya Kitaoka |
120a6e |
void rightButtonDrag(const TMouseEvent &e);
|
|
Shinya Kitaoka |
120a6e |
void rightButtonUp(const TMouseEvent &e);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void middleButtonDown(const TMouseEvent &e);
|
|
Shinya Kitaoka |
120a6e |
void middleButtonDrag(const TMouseEvent &e);
|
|
Shinya Kitaoka |
120a6e |
void middleButtonUp(const TMouseEvent &e);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void mouseWheel(const TMouseEvent &, int wheel);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void leftButtonDoubleClick(const TMouseEvent &);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TDropSource::DropEffect onEnter(const TDragDropListener::Event &event);
|
|
Shinya Kitaoka |
120a6e |
TDropSource::DropEffect onOver(const TDragDropListener::Event &event);
|
|
Shinya Kitaoka |
120a6e |
TDropSource::DropEffect onDrop(const TDragDropListener::Event &event);
|
|
Shinya Kitaoka |
120a6e |
void onLeave();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// to override
|
|
Shinya Kitaoka |
120a6e |
virtual void onSelect(TTreeViewItem *item){};
|
|
Shinya Kitaoka |
120a6e |
virtual bool startDragDrop(TTreeViewItem *item) { return false; }
|
|
Shinya Kitaoka |
120a6e |
virtual void onExpand(TTreeViewItem *item){};
|
|
Shinya Kitaoka |
120a6e |
virtual void onCollapse(TTreeViewItem *item){};
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// queries
|
|
Shinya Kitaoka |
120a6e |
int getSelectedItemCount() const;
|
|
Shinya Kitaoka |
120a6e |
TTreeViewItem *getSelectedItem(int index = 0) const;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// selection
|
|
Shinya Kitaoka |
120a6e |
void selectNone();
|
|
Shinya Kitaoka |
120a6e |
void select(TTreeViewItem *item);
|
|
Shinya Kitaoka |
120a6e |
void selectParent();
|
|
Shinya Kitaoka |
120a6e |
void selectSon(string sonName);
|
|
Shinya Kitaoka |
120a6e |
void selectItem(int index); // provvisorio
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// refresh
|
|
Shinya Kitaoka |
120a6e |
void refreshCurrentItem();
|
|
Shinya Kitaoka |
120a6e |
void refresh();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// tooltips &helps
|
|
Shinya Kitaoka |
120a6e |
wstring getTooltipString(const TPoint &);
|
|
Shinya Kitaoka |
120a6e |
string getContextHelpReference(const TPoint &p);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifndef MACOSX
|
|
Shinya Kitaoka |
120a6e |
// togliere l'ifdef con il gcc3.3.2
|
|
Shinya Kitaoka |
120a6e |
void onItemChange();
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// misc
|
|
Shinya Kitaoka |
120a6e |
void scrollToX(int x);
|
|
Shinya Kitaoka |
120a6e |
void scrollToY(int y);
|
|
Shinya Kitaoka |
120a6e |
void renameCurrentItem(wstring s);
|
|
Shinya Kitaoka |
120a6e |
void updateVisibleItems();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
protected:
|
|
Shinya Kitaoka |
120a6e |
void getPlacement(int index, TRect &rect);
|
|
Shinya Kitaoka |
120a6e |
int getIndexFromY(int y);
|
|
Shinya Kitaoka |
120a6e |
void addItemAndSons(TTreeViewItem *item, int indentation);
|
|
Shinya Kitaoka |
120a6e |
void updateScrollbars();
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#endif
|