1 ////////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/listctrlcmn.cpp
3 // Purpose: Common defines for wxListCtrl and wxListCtrl-based classes.
4 // Author: Kevin Ollivier
7 // Copyright: (c) Kevin Ollivier
8 // Licence: wxWindows licence
9 ////////////////////////////////////////////////////////////////////////////////
11 // =============================================================================
13 // =============================================================================
15 // -----------------------------------------------------------------------------
17 // -----------------------------------------------------------------------------
19 // For compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
28 #include "wx/listctrl.h"
31 #include "wx/dcclient.h"
34 const char wxListCtrlNameStr
[] = "listCtrl";
37 wxDEFINE_EVENT( wxEVT_COMMAND_LIST_BEGIN_DRAG
, wxListEvent
);
38 wxDEFINE_EVENT( wxEVT_COMMAND_LIST_BEGIN_RDRAG
, wxListEvent
);
39 wxDEFINE_EVENT( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, wxListEvent
);
40 wxDEFINE_EVENT( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, wxListEvent
);
41 wxDEFINE_EVENT( wxEVT_COMMAND_LIST_DELETE_ITEM
, wxListEvent
);
42 wxDEFINE_EVENT( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, wxListEvent
);
43 wxDEFINE_EVENT( wxEVT_COMMAND_LIST_ITEM_SELECTED
, wxListEvent
);
44 wxDEFINE_EVENT( wxEVT_COMMAND_LIST_ITEM_DESELECTED
, wxListEvent
);
45 wxDEFINE_EVENT( wxEVT_COMMAND_LIST_KEY_DOWN
, wxListEvent
);
46 wxDEFINE_EVENT( wxEVT_COMMAND_LIST_INSERT_ITEM
, wxListEvent
);
47 wxDEFINE_EVENT( wxEVT_COMMAND_LIST_COL_CLICK
, wxListEvent
);
48 wxDEFINE_EVENT( wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
, wxListEvent
);
49 wxDEFINE_EVENT( wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
, wxListEvent
);
50 wxDEFINE_EVENT( wxEVT_COMMAND_LIST_COL_DRAGGING
, wxListEvent
);
51 wxDEFINE_EVENT( wxEVT_COMMAND_LIST_COL_END_DRAG
, wxListEvent
);
52 wxDEFINE_EVENT( wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, wxListEvent
);
53 wxDEFINE_EVENT( wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
, wxListEvent
);
54 wxDEFINE_EVENT( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
, wxListEvent
);
55 wxDEFINE_EVENT( wxEVT_COMMAND_LIST_ITEM_FOCUSED
, wxListEvent
);
56 wxDEFINE_EVENT( wxEVT_COMMAND_LIST_CACHE_HINT
, wxListEvent
);
58 // -----------------------------------------------------------------------------
60 // -----------------------------------------------------------------------------
62 wxDEFINE_FLAGS( wxListCtrlStyle
)
63 wxBEGIN_FLAGS( wxListCtrlStyle
)
64 // new style border flags, we put them first to
65 // use them for streaming out
66 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
67 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
68 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
69 wxFLAGS_MEMBER(wxBORDER_RAISED
)
70 wxFLAGS_MEMBER(wxBORDER_STATIC
)
71 wxFLAGS_MEMBER(wxBORDER_NONE
)
73 // old style border flags
74 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
75 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
76 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
77 wxFLAGS_MEMBER(wxRAISED_BORDER
)
78 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
79 wxFLAGS_MEMBER(wxBORDER
)
81 // standard window styles
82 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
83 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
84 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
85 wxFLAGS_MEMBER(wxWANTS_CHARS
)
86 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
87 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
88 wxFLAGS_MEMBER(wxVSCROLL
)
89 wxFLAGS_MEMBER(wxHSCROLL
)
91 wxFLAGS_MEMBER(wxLC_LIST
)
92 wxFLAGS_MEMBER(wxLC_REPORT
)
93 wxFLAGS_MEMBER(wxLC_ICON
)
94 wxFLAGS_MEMBER(wxLC_SMALL_ICON
)
95 wxFLAGS_MEMBER(wxLC_ALIGN_TOP
)
96 wxFLAGS_MEMBER(wxLC_ALIGN_LEFT
)
97 wxFLAGS_MEMBER(wxLC_AUTOARRANGE
)
98 wxFLAGS_MEMBER(wxLC_USER_TEXT
)
99 wxFLAGS_MEMBER(wxLC_EDIT_LABELS
)
100 wxFLAGS_MEMBER(wxLC_NO_HEADER
)
101 wxFLAGS_MEMBER(wxLC_SINGLE_SEL
)
102 wxFLAGS_MEMBER(wxLC_SORT_ASCENDING
)
103 wxFLAGS_MEMBER(wxLC_SORT_DESCENDING
)
104 wxFLAGS_MEMBER(wxLC_VIRTUAL
)
105 wxEND_FLAGS( wxListCtrlStyle
)
107 #if ((!defined(__WXMSW__) && !(defined(__WXMAC__) && wxOSX_USE_CARBON)) || defined(__WXUNIVERSAL__))
108 wxIMPLEMENT_DYNAMIC_CLASS_XTI(wxListCtrl
, wxGenericListCtrl
, "wx/listctrl.h")
110 wxIMPLEMENT_DYNAMIC_CLASS_XTI(wxListCtrl
, wxControl
, "wx/listctrl.h")
113 wxBEGIN_PROPERTIES_TABLE(wxListCtrl
)
114 wxEVENT_PROPERTY( TextUpdated
, wxEVT_COMMAND_TEXT_UPDATED
, wxCommandEvent
)
116 wxPROPERTY_FLAGS( WindowStyle
, wxListCtrlStyle
, long, SetWindowStyleFlag
, \
117 GetWindowStyleFlag
, wxEMPTY_PARAMETER_VALUE
, 0 /*flags*/, \
118 wxT("Helpstring"), wxT("group")) // style
119 wxEND_PROPERTIES_TABLE()
121 wxEMPTY_HANDLERS_TABLE(wxListCtrl
)
123 wxCONSTRUCTOR_5( wxListCtrl
, wxWindow
*, Parent
, wxWindowID
, Id
, \
124 wxPoint
, Position
, wxSize
, Size
, long, WindowStyle
)
127 TODO : Expose more information of a list's layout etc. via appropriate objects
128 (see NotebookPageInfo)
131 IMPLEMENT_DYNAMIC_CLASS(wxListView
, wxListCtrl
)
132 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
133 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
135 // ----------------------------------------------------------------------------
136 // wxListCtrlBase implementation
137 // ----------------------------------------------------------------------------
140 wxListCtrlBase::AppendColumn(const wxString
& heading
,
144 return InsertColumn(GetColumnCount(), heading
, format
, width
);
148 wxListCtrlBase::InsertColumn(long col
,
149 const wxString
& heading
,
154 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
155 item
.m_text
= heading
;
157 || width
== wxLIST_AUTOSIZE
158 || width
== wxLIST_AUTOSIZE_USEHEADER
)
160 item
.m_mask
|= wxLIST_MASK_WIDTH
;
161 item
.m_width
= width
;
163 item
.m_format
= format
;
165 return InsertColumn(col
, item
);
168 long wxListCtrlBase::InsertColumn(long col
, const wxListItem
& info
)
170 long rc
= DoInsertColumn(col
, info
);
173 // As our best size calculation depends on the column headers,
174 // invalidate the previously cached best size when a column is added.
175 InvalidateBestSize();
181 wxSize
wxListCtrlBase::DoGetBestClientSize() const
183 // There is no obvious way to determine the best size in icon and list
184 // modes so just don't do it for now.
185 if ( !InReportView() )
186 return wxControl::DoGetBestClientSize();
188 // In report mode, we use only the column headers, not items, to determine
189 // the best width. The reason for this is that it's easier (we can't just
190 // iterate over all items, especially not in a virtual control, so we'd
191 // have to do something relatively complicated such as checking the size of
192 // some items in the beginning and the end only) and also because the
193 // columns are usually static while the list contents is dynamic so it
194 // usually doesn't make much sense to adjust the control size to it anyhow.
195 // And finally, scrollbars can always be used with the items while the
196 // headers are just truncated if there is not enough place for them.
197 const int columns
= GetColumnCount();
198 if ( HasFlag(wxLC_NO_HEADER
) || !columns
)
199 return wxControl::DoGetBestClientSize();
201 wxClientDC
dc(const_cast<wxListCtrlBase
*>(this));
203 // Total width of all headers determines the best control width.
205 for ( int col
= 0; col
< columns
; col
++ )
207 totalWidth
+= GetColumnWidth(col
);
210 // Use some arbitrary height, there is no good way to determine it.
211 return wxSize(totalWidth
, 10*dc
.GetCharHeight());
214 #endif // wxUSE_LISTCTRL