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-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
|
|
|
|
explicit FListViewItem (FListViewItem*);
|
|
|
|
explicit FListViewItem (FListView*);
|
2017-09-15 01:31:02 +02:00
|
|
|
explicit FListViewItem (FObjectIterator);
|
2017-09-11 03:06:02 +02:00
|
|
|
FListViewItem ( const std::vector<FString>&
|
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-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-15 01:31:02 +02:00
|
|
|
std::vector<FString> column_list;
|
2017-09-11 03:06:02 +02:00
|
|
|
FWidget::data_ptr data_pointer;
|
|
|
|
int visible_lines;
|
|
|
|
bool expandable;
|
|
|
|
bool is_expand;
|
|
|
|
|
|
|
|
// 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
|
|
|
|
const char* getClassName() const;
|
2017-09-16 01:21:16 +02:00
|
|
|
uInt getCount() const;
|
2017-09-11 03:06:02 +02:00
|
|
|
fc::text_alignment getColumnAlignment (int) const;
|
|
|
|
FString getColumnText (int) const;
|
2017-09-15 01:31:02 +02:00
|
|
|
FListViewItem* getCurrentItem();
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Mutators
|
|
|
|
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();
|
|
|
|
|
|
|
|
// Methods
|
|
|
|
virtual int addColumn (const FString&, int = USE_MAX_SIZE);
|
2017-09-15 01:31:02 +02:00
|
|
|
FObjectIterator insert (FListViewItem*);
|
|
|
|
FObjectIterator insert (FListViewItem*, FObjectIterator);
|
|
|
|
FObjectIterator insert ( const std::vector<FString>&
|
|
|
|
, data_ptr = 0 );
|
|
|
|
FObjectIterator insert ( const std::vector<FString>&
|
|
|
|
, FObjectIterator );
|
|
|
|
FObjectIterator insert ( const std::vector<FString>&
|
|
|
|
, 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 );
|
2017-09-17 01:50:41 +02:00
|
|
|
FObjectIterator beginOfList();
|
|
|
|
FObjectIterator endOfList();
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Event handlers
|
|
|
|
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*);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// Methods
|
|
|
|
void adjustYOffset();
|
|
|
|
void adjustSize();
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
// Constants
|
|
|
|
static const int USE_MAX_SIZE = -1;
|
|
|
|
|
|
|
|
// Disable copy constructor
|
|
|
|
FListView (const FListView&);
|
|
|
|
|
|
|
|
// Disable assignment operator (=)
|
|
|
|
FListView& operator = (const FListView&);
|
|
|
|
|
|
|
|
// Methods
|
|
|
|
void init();
|
|
|
|
uInt getAlignOffset (fc::text_alignment, uInt, uInt);
|
|
|
|
void draw();
|
|
|
|
void drawColumnLabels();
|
|
|
|
void drawList();
|
2017-09-16 01:21:16 +02:00
|
|
|
void drawListLine (const FListViewItem*, bool, bool);
|
2017-09-11 03:06:02 +02:00
|
|
|
void recalculateHorizontalBar (int);
|
|
|
|
void recalculateVerticalBar (int);
|
2017-09-16 01:21:16 +02:00
|
|
|
FObjectIterator appendItem (FListViewItem*);
|
2017-09-11 03:06:02 +02:00
|
|
|
void processClick();
|
|
|
|
void processChanged();
|
2017-09-15 01:31:02 +02:00
|
|
|
FObjectIterator index2iterator (int);
|
2017-09-16 01:21:16 +02:00
|
|
|
void nextElement (FObjectIterator&);
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Callback methods
|
|
|
|
void cb_VBarChange (FWidget*, data_ptr);
|
|
|
|
void cb_HBarChange (FWidget*, data_ptr);
|
|
|
|
|
|
|
|
// Data Members
|
2017-09-15 01:31:02 +02:00
|
|
|
FObjectIterator root;
|
|
|
|
FObjectList selflist;
|
|
|
|
FObjectList itemlist;
|
2017-09-11 03:06:02 +02:00
|
|
|
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;
|
|
|
|
|
|
|
|
// 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
|
|
|
|
FListView::insert ( const std::vector<FString>& cols, data_ptr d )
|
|
|
|
{ return insert (cols, d, root); }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline FObject::FObjectIterator
|
|
|
|
FListView::insert ( const std::vector<FString>& cols
|
|
|
|
, 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);
|
|
|
|
|
|
|
|
if ( item->isExpandable() )
|
|
|
|
{
|
|
|
|
//iter = item->begin();
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
++iter;
|
2017-09-16 01:21:16 +02:00
|
|
|
}
|
|
|
|
|
2017-07-18 23:50:51 +02:00
|
|
|
#endif // FLISTVIEW_H
|