mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-12 13:37:00 -04:00
Added a 'tree list' control, which will be used for the package/updates window to be able to group packages
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@775 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
//+----------------------------------------------------------------------------+
|
||||
//| 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
|
||||
Reference in New Issue
Block a user