2017-07-18 23:50:51 +02:00
|
|
|
// File: flistview.h
|
|
|
|
// Provides: class FListViewItem
|
|
|
|
// class FListView
|
|
|
|
//
|
|
|
|
// Inheritance diagram
|
|
|
|
// ═══════════════════
|
|
|
|
//
|
|
|
|
// ▕▔▔▔▔▔▔▔▔▔▏ ▕▔▔▔▔▔▔▔▔▔▏
|
|
|
|
// ▕ FObject ▏ ▕ FTerm ▏
|
|
|
|
// ▕▁▁▁▁▁▁▁▁▁▏ ▕▁▁▁▁▁▁▁▁▁▏
|
|
|
|
// ▲ ▲
|
|
|
|
// │ │
|
|
|
|
// └─────┬─────┘
|
|
|
|
// │
|
|
|
|
// ▕▔▔▔▔▔▔▔▔▏
|
|
|
|
// ▕ FVTerm ▏
|
|
|
|
// ▕▁▁▁▁▁▁▁▁▏
|
|
|
|
// ▲
|
|
|
|
// │
|
2017-09-16 01:21:16 +02:00
|
|
|
// ▕▔▔▔▔▔▔▔▔▔▏ ▕▔▔▔▔▔▔▔▔▔▏
|
|
|
|
// ▕ FWidget ▏ ▕ FObject ▏
|
|
|
|
// ▕▁▁▁▁▁▁▁▁▁▏ ▕▁▁▁▁▁▁▁▁▁▏
|
|
|
|
// ▲ ▲
|
|
|
|
// │ │
|
2017-07-18 23:50:51 +02:00
|
|
|
// ▕▔▔▔▔▔▔▔▔▔▔▔▏1 *▕▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▏
|
|
|
|
// ▕ FListView ▏- - - -▕ FListViewItem ▏
|
|
|
|
// ▕▁▁▁▁▁▁▁▁▁▁▁▏ ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef FLISTVIEW_H
|
|
|
|
#define FLISTVIEW_H
|
|
|
|
|
2017-09-19 06:18:03 +02:00
|
|
|
#include <stack>
|
2017-09-11 03:06:02 +02:00
|
|
|
#include <vector>
|
|
|
|
|
2017-09-17 21:32:46 +02:00
|
|
|
#include "final/fscrollbar.h"
|
|
|
|
#include "final/fstring.h"
|
|
|
|
#include "final/ftermbuffer.h"
|
|
|
|
#include "final/fwidget.h"
|
2017-07-18 23:50:51 +02:00
|
|
|
|
|
|
|
// class forward declaration
|
|
|
|
class FListView;
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class FListViewItem
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
#pragma pack(push)
|
|
|
|
#pragma pack(1)
|
|
|
|
|
|
|
|
class FListViewItem : public FObject
|
|
|
|
{
|
2017-09-11 03:06:02 +02:00
|
|
|
public:
|
|
|
|
// Constructor
|
|
|
|
FListViewItem (const FListViewItem&); // copy constructor
|
2017-09-15 01:31:02 +02:00
|
|
|
explicit FListViewItem (FObjectIterator);
|
2017-09-20 16:56:20 +02:00
|
|
|
FListViewItem ( const FStringList&
|
2017-09-15 01:31:02 +02:00
|
|
|
, FWidget::data_ptr
|
|
|
|
, FObjectIterator );
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Destructor
|
|
|
|
~FListViewItem();
|
|
|
|
|
|
|
|
// Assignment operator (=)
|
|
|
|
FListViewItem& operator = (const FListViewItem&);
|
|
|
|
|
|
|
|
// Accessors
|
2017-09-16 01:21:16 +02:00
|
|
|
const char* getClassName() const;
|
|
|
|
uInt getColumnCount() const;
|
|
|
|
FString getText (int) const;
|
2017-09-19 06:18:03 +02:00
|
|
|
uInt getDepth() const;
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Mutator
|
2017-09-16 01:21:16 +02:00
|
|
|
void setText (int, const FString&);
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Inquiry
|
2017-09-16 01:21:16 +02:00
|
|
|
bool isExpand();
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Methods
|
2017-09-16 01:21:16 +02:00
|
|
|
FObjectIterator insert (FListViewItem*);
|
|
|
|
FObjectIterator insert (FListViewItem*, FObjectIterator);
|
|
|
|
void expand();
|
|
|
|
void collapse();
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
// Inquiry
|
2017-09-16 01:21:16 +02:00
|
|
|
bool isExpandable();
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Methods
|
2017-09-16 01:21:16 +02:00
|
|
|
FObjectIterator appendItem (FListViewItem*);
|
|
|
|
void replaceControlCodes();
|
|
|
|
int getVisibleLines();
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Data Member
|
2017-09-20 16:56:20 +02:00
|
|
|
FStringList column_list;
|
|
|
|
FWidget::data_ptr data_pointer;
|
|
|
|
int visible_lines;
|
|
|
|
bool expandable;
|
|
|
|
bool is_expand;
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Friend class
|
|
|
|
friend class FListView;
|
2017-07-18 23:50:51 +02:00
|
|
|
};
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
|
|
|
|
|
|
|
// FListViewItem inline functions
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline const char* FListViewItem::getClassName() const
|
|
|
|
{ return "FListViewItem"; }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-08-20 17:30:30 +02:00
|
|
|
inline uInt FListViewItem::getColumnCount() const
|
2017-09-15 01:31:02 +02:00
|
|
|
{ return uInt(column_list.size()); }
|
2017-07-18 23:50:51 +02:00
|
|
|
|
2017-08-20 17:30:30 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool FListViewItem::isExpand()
|
|
|
|
{ return is_expand; }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool FListViewItem::isExpandable()
|
|
|
|
{ return expandable; }
|
|
|
|
|
2017-07-18 23:50:51 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class FListView
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
#pragma pack(push)
|
|
|
|
#pragma pack(1)
|
|
|
|
|
|
|
|
class FListView : public FWidget
|
|
|
|
{
|
2017-09-11 03:06:02 +02:00
|
|
|
public:
|
|
|
|
// Using-declaration
|
|
|
|
using FWidget::setGeometry;
|
|
|
|
|
|
|
|
// Constructor
|
|
|
|
explicit FListView (FWidget* = 0);
|
|
|
|
|
|
|
|
// Destructor
|
|
|
|
~FListView();
|
|
|
|
|
|
|
|
// Accessors
|
2017-09-19 06:18:03 +02:00
|
|
|
const char* getClassName() const;
|
|
|
|
uInt getCount() const;
|
|
|
|
fc::text_alignment getColumnAlignment (int) const;
|
|
|
|
FString getColumnText (int) const;
|
|
|
|
FListViewItem* getCurrentItem();
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Mutators
|
2017-09-19 06:18:03 +02:00
|
|
|
void setGeometry (int, int, int, int, bool = true);
|
|
|
|
void setColumnAlignment (int, fc::text_alignment);
|
|
|
|
void setColumnText (int, const FString&);
|
|
|
|
bool setTreeView (bool);
|
|
|
|
bool setTreeView();
|
|
|
|
bool unsetTreeView();
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Methods
|
2017-09-19 06:18:03 +02:00
|
|
|
virtual int addColumn (const FString&, int = USE_MAX_SIZE);
|
|
|
|
FObjectIterator insert (FListViewItem*);
|
|
|
|
FObjectIterator insert (FListViewItem*, FObjectIterator);
|
2017-09-20 16:56:20 +02:00
|
|
|
FObjectIterator insert ( const FStringList&
|
2017-09-19 06:18:03 +02:00
|
|
|
, data_ptr = 0 );
|
2017-09-20 16:56:20 +02:00
|
|
|
FObjectIterator insert ( const FStringList&
|
2017-09-19 06:18:03 +02:00
|
|
|
, FObjectIterator );
|
2017-09-20 16:56:20 +02:00
|
|
|
FObjectIterator insert ( const FStringList&
|
2017-09-19 06:18:03 +02:00
|
|
|
, data_ptr
|
|
|
|
, FObjectIterator );
|
|
|
|
FObjectIterator insert ( const std::vector<long>&
|
|
|
|
, data_ptr = 0 );
|
|
|
|
FObjectIterator insert ( const std::vector<long>&
|
|
|
|
, FObjectIterator );
|
|
|
|
FObjectIterator insert ( const std::vector<long>&
|
|
|
|
, data_ptr
|
|
|
|
, FObjectIterator );
|
|
|
|
FObjectIterator beginOfList();
|
|
|
|
FObjectIterator endOfList();
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Event handlers
|
2017-09-19 06:18:03 +02:00
|
|
|
void onKeyPress (FKeyEvent*);
|
|
|
|
void onMouseDown (FMouseEvent*);
|
|
|
|
void onMouseUp (FMouseEvent*);
|
|
|
|
void onMouseMove (FMouseEvent*);
|
|
|
|
void onMouseDoubleClick (FMouseEvent*);
|
|
|
|
void onWheel (FWheelEvent*);
|
|
|
|
void onTimer (FTimerEvent*);
|
|
|
|
void onFocusIn (FFocusEvent*);
|
|
|
|
void onFocusOut (FFocusEvent*);
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
// Methods
|
2017-09-19 06:18:03 +02:00
|
|
|
void adjustYOffset();
|
|
|
|
void adjustSize();
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
// Typedef
|
|
|
|
struct Header
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Header()
|
|
|
|
: name()
|
|
|
|
, width (0)
|
|
|
|
, fixed_width (false)
|
|
|
|
, alignment (fc::alignLeft)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
~Header()
|
|
|
|
{ }
|
|
|
|
|
|
|
|
FString name;
|
|
|
|
int width;
|
|
|
|
bool fixed_width;
|
|
|
|
fc::text_alignment alignment;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::vector<Header> headerItems;
|
2017-09-19 06:18:03 +02:00
|
|
|
typedef std::stack<FObjectIterator> FObjectIteratorStack;
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Constants
|
|
|
|
static const int USE_MAX_SIZE = -1;
|
|
|
|
|
|
|
|
// Disable copy constructor
|
|
|
|
FListView (const FListView&);
|
|
|
|
|
|
|
|
// Disable assignment operator (=)
|
|
|
|
FListView& operator = (const FListView&);
|
|
|
|
|
|
|
|
// Methods
|
2017-09-19 06:18:03 +02:00
|
|
|
void init();
|
|
|
|
uInt getAlignOffset (fc::text_alignment, uInt, uInt);
|
|
|
|
void draw();
|
|
|
|
void drawColumnLabels();
|
|
|
|
void drawList();
|
|
|
|
void drawListLine (const FListViewItem*, bool, bool);
|
|
|
|
void recalculateHorizontalBar (int);
|
|
|
|
void recalculateVerticalBar (int);
|
|
|
|
FObjectIterator appendItem (FListViewItem*);
|
|
|
|
void processClick();
|
|
|
|
void processChanged();
|
|
|
|
FObjectIterator index2iterator (int);
|
|
|
|
void nextElement (FObjectIterator&);
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Callback methods
|
2017-09-19 06:18:03 +02:00
|
|
|
void cb_VBarChange (FWidget*, data_ptr);
|
|
|
|
void cb_HBarChange (FWidget*, data_ptr);
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Data Members
|
2017-09-19 06:18:03 +02:00
|
|
|
FObjectIterator root;
|
|
|
|
FObjectList selflist;
|
|
|
|
FObjectList itemlist;
|
|
|
|
FObjectIteratorStack iter_path;
|
|
|
|
headerItems header;
|
|
|
|
FTermBuffer headerline;
|
|
|
|
FScrollbar* vbar;
|
|
|
|
FScrollbar* hbar;
|
|
|
|
fc::dragScroll drag_scroll;
|
|
|
|
int scroll_repeat;
|
|
|
|
int scroll_distance;
|
|
|
|
bool scroll_timer;
|
|
|
|
bool tree_view;
|
|
|
|
int current;
|
|
|
|
int xoffset;
|
|
|
|
int yoffset;
|
|
|
|
int nf_offset;
|
|
|
|
int max_line_width;
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Friend class
|
|
|
|
friend class FListViewItem;
|
2017-07-18 23:50:51 +02:00
|
|
|
};
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
|
|
|
|
|
|
|
// FListView inline functions
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline const char* FListView::getClassName() const
|
|
|
|
{ return "FListView"; }
|
|
|
|
|
2017-09-16 01:21:16 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline uInt FListView::getCount() const
|
|
|
|
{ return uInt(itemlist.size()); }
|
|
|
|
|
2017-08-01 00:56:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
2017-09-15 01:31:02 +02:00
|
|
|
inline FListViewItem* FListView::getCurrentItem()
|
|
|
|
{
|
|
|
|
FObjectIterator iter = itemlist.begin();
|
|
|
|
std::advance (iter, current - 1);
|
|
|
|
return static_cast<FListViewItem*>(*iter);
|
|
|
|
}
|
2017-08-01 00:56:12 +02:00
|
|
|
|
2017-08-20 17:30:30 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool FListView::setTreeView (bool on)
|
2017-09-17 21:32:46 +02:00
|
|
|
{ return tree_view = ( on ) ? true : false; }
|
2017-08-20 17:30:30 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool FListView::setTreeView()
|
|
|
|
{ return setTreeView(true); }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool FListView::unsetTreeView()
|
|
|
|
{ return setTreeView(false); }
|
|
|
|
|
2017-07-18 23:50:51 +02:00
|
|
|
//----------------------------------------------------------------------
|
2017-09-15 01:31:02 +02:00
|
|
|
inline FObject::FObjectIterator FListView::insert (FListViewItem* item)
|
|
|
|
{ return insert (item, root); }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline FObject::FObjectIterator
|
2017-09-20 16:56:20 +02:00
|
|
|
FListView::insert ( const FStringList& cols, data_ptr d )
|
2017-09-15 01:31:02 +02:00
|
|
|
{ return insert (cols, d, root); }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline FObject::FObjectIterator
|
2017-09-20 16:56:20 +02:00
|
|
|
FListView::insert ( const FStringList& cols
|
2017-09-15 01:31:02 +02:00
|
|
|
, FObjectIterator parent_iter )
|
|
|
|
{ return insert (cols, 0, parent_iter); }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline FObject::FObjectIterator
|
|
|
|
FListView::insert ( const std::vector<long>& cols, data_ptr d )
|
|
|
|
{ return insert (cols, d, root); }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline FObject::FObjectIterator
|
|
|
|
FListView::insert ( const std::vector<long>& cols
|
|
|
|
, FObjectIterator parent_iter )
|
|
|
|
{ return insert (cols, 0, parent_iter); }
|
|
|
|
|
2017-09-17 01:50:41 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline FObject::FObjectIterator FListView::beginOfList()
|
|
|
|
{ return itemlist.begin(); }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline FObject::FObjectIterator FListView::endOfList()
|
|
|
|
{ return itemlist.end(); }
|
|
|
|
|
2017-09-15 01:31:02 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline FObject::FObjectIterator FListView::index2iterator (int index)
|
2017-07-18 23:50:51 +02:00
|
|
|
{
|
2017-09-15 01:31:02 +02:00
|
|
|
FObjectIterator iter = itemlist.begin();
|
2017-07-18 23:50:51 +02:00
|
|
|
std::advance (iter, index);
|
|
|
|
return iter;
|
|
|
|
}
|
|
|
|
|
2017-09-16 01:21:16 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FListView::nextElement (FObjectIterator& iter)
|
|
|
|
{
|
2017-09-17 01:50:41 +02:00
|
|
|
FListViewItem* item = static_cast<FListViewItem*>(*iter);
|
|
|
|
|
2017-09-19 06:18:03 +02:00
|
|
|
if ( item->isExpandable() && item->isExpand() )
|
2017-09-17 01:50:41 +02:00
|
|
|
{
|
2017-09-19 06:18:03 +02:00
|
|
|
iter_path.push(iter);
|
|
|
|
iter = item->begin();
|
2017-09-17 01:50:41 +02:00
|
|
|
}
|
|
|
|
else
|
2017-09-19 06:18:03 +02:00
|
|
|
{
|
2017-09-17 01:50:41 +02:00
|
|
|
++iter;
|
2017-09-19 06:18:03 +02:00
|
|
|
|
|
|
|
if ( ! iter_path.empty() )
|
|
|
|
{
|
|
|
|
FObjectIterator& parent_iter = iter_path.top();
|
|
|
|
|
|
|
|
if ( iter == (*parent_iter)->end() )
|
|
|
|
{
|
|
|
|
iter = parent_iter;
|
|
|
|
iter_path.pop();
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-09-16 01:21:16 +02:00
|
|
|
}
|
|
|
|
|
2017-07-18 23:50:51 +02:00
|
|
|
#endif // FLISTVIEW_H
|