X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/82a5f02c861e8d57ba8255a9553b941118ad4520..bd73ba41f93a040ecf9c18040d7f788992d0a6ec:/include/wx/listctrl.h diff --git a/include/wx/listctrl.h b/include/wx/listctrl.h index bba686acd8..f0630f8a8f 100644 --- a/include/wx/listctrl.h +++ b/include/wx/listctrl.h @@ -16,6 +16,8 @@ #pragma interface "listctrlbase.h" #endif +#if wxUSE_LISTCTRL + // ---------------------------------------------------------------------------- // types // ---------------------------------------------------------------------------- @@ -27,6 +29,43 @@ typedef int (wxCALLBACK *wxListCtrlCompare)(long item1, long item2, long sortDat // wxListCtrl constants // ---------------------------------------------------------------------------- +// style flags +#define wxLC_VRULES 0x0001 +#define wxLC_HRULES 0x0002 + +#define wxLC_ICON 0x0004 +#define wxLC_SMALL_ICON 0x0008 +#define wxLC_LIST 0x0010 +#define wxLC_REPORT 0x0020 + +#define wxLC_ALIGN_TOP 0x0040 +#define wxLC_ALIGN_LEFT 0x0080 +#define wxLC_AUTOARRANGE 0x0100 +#define wxLC_VIRTUAL 0x0200 +#define wxLC_EDIT_LABELS 0x0400 +#define wxLC_NO_HEADER 0x0800 +#define wxLC_NO_SORT_HEADER 0x1000 +#define wxLC_SINGLE_SEL 0x2000 +#define wxLC_SORT_ASCENDING 0x4000 +#define wxLC_SORT_DESCENDING 0x8000 + +#define wxLC_MASK_TYPE (wxLC_ICON | wxLC_SMALL_ICON | wxLC_LIST | wxLC_REPORT) +#define wxLC_MASK_ALIGN (wxLC_ALIGN_TOP | wxLC_ALIGN_LEFT) +#define wxLC_MASK_SORT (wxLC_SORT_ASCENDING | wxLC_SORT_DESCENDING) + +// for compatibility only +#define wxLC_USER_TEXT wxLC_VIRTUAL + +// Omitted because +// (a) too much detail +// (b) not enough style flags +// (c) not implemented anyhow in the generic version +// +// #define wxLC_NO_SCROLL +// #define wxLC_NO_LABEL_WRAP +// #define wxLC_OWNERDRAW_FIXED +// #define wxLC_SHOW_SEL_ALWAYS + // Mask flags to tell app/GUI what fields of wxListItem are valid #define wxLIST_MASK_STATE 0x0001 #define wxLIST_MASK_TEXT 0x0002 @@ -239,26 +278,80 @@ private: // include the wxListCtrl class declaration // ---------------------------------------------------------------------------- -#if defined(__WXMSW__) - #ifdef __WIN16__ - #include "wx/generic/listctrl.h" - #else - #include "wx/msw/listctrl.h" - #endif -#elif defined(__WXMOTIF__) - #include "wx/generic/listctrl.h" -#elif defined(__WXGTK__) - #include "wx/generic/listctrl.h" -#elif defined(__WXQT__) - #include "wx/generic/listctrl.h" -#elif defined(__WXMAC__) - #include "wx/generic/listctrl.h" -#elif defined(__WXPM__) - #include "wx/generic/listctrl.h" -#elif defined(__WXSTUBS__) +#if defined(__WIN32__) && !defined(__WXUNIVERSAL__) + #include "wx/msw/listctrl.h" +#else #include "wx/generic/listctrl.h" #endif +// ---------------------------------------------------------------------------- +// wxListView: a class which provides a better API for list control +// ---------------------------------------------------------------------------- + +class WXDLLEXPORT wxListView : public wxListCtrl +{ +public: + wxListView() { } + wxListView( wxWindow *parent, + wxWindowID id = -1, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxLC_REPORT, + const wxValidator& validator = wxDefaultValidator, + const wxString &name = "listctrl" ) + { + Create(parent, id, pos, size, style, wxDefaultValidator, name); + } + + // focus/selection stuff + // --------------------- + + // [de]select an item + void Select(long n, bool on = TRUE) + { + SetItemState(n, on ? wxLIST_STATE_SELECTED : 0, wxLIST_STATE_SELECTED); + } + + // focus and show the given item + void Focus(long index) + { + SetItemState(index, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED); + EnsureVisible(index); + } + + // get the currently focused item or -1 if none + long GetFocusedItem() const + { + return GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED); + } + + // get first and subsequent selected items, return -1 when no more + long GetNextSelected(long item) const + { return GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); } + long GetFirstSelected() const + { return GetNextSelected(-1); } + + // return TRUE if the item is selected + bool IsSelected(long index) + { return GetItemState(index, wxLIST_STATE_SELECTED) != 0; } + + // columns + // ------- + + void SetColumnImage(int col, int image) + { + wxListItem item; + item.SetMask(wxLIST_MASK_IMAGE); + item.SetImage(image); + SetColumn(col, item); + } + + void ClearColumnImage(int col) { SetColumnImage(col, -1); } + +private: + DECLARE_DYNAMIC_CLASS(wxListView) +}; + // ---------------------------------------------------------------------------- // wxListEvent - the event class for the wxListCtrl notifications // ---------------------------------------------------------------------------- @@ -291,30 +384,72 @@ public: long GetMask() const { return m_item.m_mask; } const wxListItem& GetItem() const { return m_item; } + // for wxEVT_COMMAND_LIST_CACHE_HINT only + long GetCacheFrom() const { return m_oldItemIndex; } + long GetCacheTo() const { return m_itemIndex; } + void CopyObject(wxObject& object_dest) const; private: DECLARE_DYNAMIC_CLASS(wxListEvent) }; +// ---------------------------------------------------------------------------- +// wxListCtrl event macros +// ---------------------------------------------------------------------------- + +BEGIN_DECLARE_EVENT_TYPES() + DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG, 700) + DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG, 701) + DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, 702) + DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT, 703) + DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM, 704) + DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS, 705) + DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO, 706) + DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO, 707) + DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED, 708) + DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED, 709) + DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN, 710) + DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM, 711) + DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK, 712) + DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, 713) + DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK, 714) + DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED, 715) + DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT, 716) + DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_RIGHT_CLICK, 717) + DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG, 718) + DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_DRAGGING, 719) + DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_END_DRAG, 720) +END_DECLARE_EVENT_TYPES() + typedef void (wxEvtHandler::*wxListEventFunction)(wxListEvent&); -#define EVT_LIST_BEGIN_DRAG(id, fn) wxEventTableEntry( wxEVT_COMMAND_LIST_BEGIN_DRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ), -#define EVT_LIST_BEGIN_RDRAG(id, fn) wxEventTableEntry( wxEVT_COMMAND_LIST_BEGIN_RDRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ), -#define EVT_LIST_BEGIN_LABEL_EDIT(id, fn) wxEventTableEntry( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ), -#define EVT_LIST_END_LABEL_EDIT(id, fn) wxEventTableEntry( wxEVT_COMMAND_LIST_END_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ), -#define EVT_LIST_DELETE_ITEM(id, fn) wxEventTableEntry( wxEVT_COMMAND_LIST_DELETE_ITEM, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ), -#define EVT_LIST_DELETE_ALL_ITEMS(id, fn) wxEventTableEntry( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ), -#define EVT_LIST_GET_INFO(id, fn) wxEventTableEntry( wxEVT_COMMAND_LIST_GET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ), -#define EVT_LIST_SET_INFO(id, fn) wxEventTableEntry( wxEVT_COMMAND_LIST_SET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ), -#define EVT_LIST_ITEM_SELECTED(id, fn) wxEventTableEntry( wxEVT_COMMAND_LIST_ITEM_SELECTED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ), -#define EVT_LIST_ITEM_DESELECTED(id, fn) wxEventTableEntry( wxEVT_COMMAND_LIST_ITEM_DESELECTED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ), -#define EVT_LIST_KEY_DOWN(id, fn) wxEventTableEntry( wxEVT_COMMAND_LIST_KEY_DOWN, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ), -#define EVT_LIST_INSERT_ITEM(id, fn) wxEventTableEntry( wxEVT_COMMAND_LIST_INSERT_ITEM, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ), -#define EVT_LIST_COL_CLICK(id, fn) wxEventTableEntry( wxEVT_COMMAND_LIST_COL_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ), -#define EVT_LIST_ITEM_RIGHT_CLICK(id, fn) wxEventTableEntry( wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, (wxObject *) NULL ), -#define EVT_LIST_ITEM_MIDDLE_CLICK(id, fn) wxEventTableEntry( wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, (wxObject *) NULL ), -#define EVT_LIST_ITEM_ACTIVATED(id, fn) wxEventTableEntry( wxEVT_COMMAND_LIST_ITEM_ACTIVATED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, (wxObject *) NULL ), +#define EVT_LIST_BEGIN_DRAG(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_BEGIN_DRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ), +#define EVT_LIST_BEGIN_RDRAG(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_BEGIN_RDRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ), +#define EVT_LIST_BEGIN_LABEL_EDIT(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ), +#define EVT_LIST_END_LABEL_EDIT(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_END_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ), +#define EVT_LIST_DELETE_ITEM(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_DELETE_ITEM, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ), +#define EVT_LIST_DELETE_ALL_ITEMS(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ), +#define EVT_LIST_GET_INFO(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_GET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ), +#define EVT_LIST_SET_INFO(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_SET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ), +#define EVT_LIST_KEY_DOWN(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_KEY_DOWN, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ), +#define EVT_LIST_INSERT_ITEM(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_INSERT_ITEM, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ), + +#define EVT_LIST_COL_CLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_COL_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ), +#define EVT_LIST_COL_RIGHT_CLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_COL_RIGHT_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ), +#define EVT_LIST_COL_BEGIN_DRAG(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_COL_BEGIN_DRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ), +#define EVT_LIST_COL_DRAGGING(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_COL_DRAGGING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ), +#define EVT_LIST_COL_END_DRAG(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_COL_END_DRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ), + +#define EVT_LIST_ITEM_SELECTED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_ITEM_SELECTED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ), +#define EVT_LIST_ITEM_DESELECTED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_ITEM_DESELECTED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ), +#define EVT_LIST_ITEM_RIGHT_CLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, (wxObject *) NULL ), +#define EVT_LIST_ITEM_MIDDLE_CLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, (wxObject *) NULL ), +#define EVT_LIST_ITEM_ACTIVATED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_ITEM_ACTIVATED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, (wxObject *) NULL ), + +#define EVT_LIST_CACHE_HINT(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_CACHE_HINT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, (wxObject *) NULL ), + +#endif // wxUSE_LISTCTRL #endif // _WX_LISTCTRL_H_BASE_