Commit bb69b4a8 authored by twanvl's avatar twanvl

Added a 'tree list' control, which will be used for the package/updates window...

Added a 'tree list' control, which will be used for the package/updates window to be able to group packages
parent b3f79483
This diff is collapsed.
//+----------------------------------------------------------------------------+
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
//| Copyright: (C) 2001 - 2007 Twan van Laarhoven |
//| License: GNU General Public License 2 or later (see file COPYING) |
//+----------------------------------------------------------------------------+
#ifndef HEADER_GUI_CONTROL_TREE_LIST
#define HEADER_GUI_CONTROL_TREE_LIST
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <wx/vscroll.h>
typedef intrusive_ptr<IntrusivePtrVirtualBase> VoidP;
// ----------------------------------------------------------------------------- : TreeList
/// A combination of a TreeCtrl and a ListCtrl. A tree with multiple columns.
class TreeList : public wxPanel {
public:
TreeList(Window* parent, int id, long style = wxSUNKEN_BORDER);
/// Expand/collapse an item
void expand(size_t item, bool expand = true);
/// Select an item
void select(size_t item);
/// (re)build the list
void rebuild(bool full = true);
public:
/// An item in the tree list
struct Item {
Item() {}
Item(int level, bool expanded = false, VoidP data = VoidP())
: level(level), expanded(expanded), data(data)
{}
int level;
bool expanded;
VoidP data;
size_t position; // NOTHING if invisible, otherwise the line the item is on
UInt lines; // lines in front of this item (bit set)
inline bool visible() const { return position != NOTHING; }
};
protected:
/// The items in the tree list
vector<Item> items;
static const size_t NOTHING = (size_t)-1;
size_t selection;
/// Initialize the items
virtual void initItems() = 0;
/// Get the text of an item
virtual String itemText(size_t item, size_t column) const = 0;
/// Get the color of an item
virtual Color itemColor(size_t item, size_t column) const = 0;
/// The number of columns
virtual size_t columnCount() const = 0;
/// The text of a column
virtual String columnText(size_t column) const = 0;
/// The width of a column in pixels
virtual int columnWidth(size_t column) const = 0;
private:
int item_height;
static const int header_height = 17;
static const int level_width = 17;
size_t total_lines; // number of shown items
size_t first_line; // first visible line
size_t visible_lines; // number of (partially) visible lines
size_t visible_lines_t; // number of totally visible lines
void calcItemCount();
size_t findItemByPos(int y) const;
size_t findItem(size_t line, size_t start = 0) const;
size_t findLastItem(size_t end) const;
size_t findParent(size_t item) const;
bool hasChildren(size_t item) const;
DECLARE_EVENT_TABLE();
void onPaint(wxPaintEvent&);
void onChar(wxKeyEvent& ev);
void onLeftDown(wxMouseEvent& ev);
void onLeftDClick(wxMouseEvent& ev);
// VScrolledWindow clone
void onSize(wxSizeEvent& ev);
void onScroll(wxScrollWinEvent& ev);
void onMouseWheel(wxMouseEvent& ev);
void ScrollToLine(size_t line);
void UpdateScrollbar();
void RefreshLine(size_t line);
};
// ----------------------------------------------------------------------------- : EOF
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment