]>
Commit | Line | Data |
---|---|---|
2bda0e17 | 1 | ///////////////////////////////////////////////////////////////////////////// |
648bec3e | 2 | // Name: src/msw/listctrl.cpp |
2bda0e17 KB |
3 | // Purpose: wxListCtrl |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
6c9a19aa | 8 | // Copyright: (c) Julian Smart |
65571936 | 9 | // Licence: wxWindows licence |
2bda0e17 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
edccf428 VZ |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
14f355c2 | 20 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
0b5efdc7 | 21 | #pragma implementation "listctrl.h" |
3c1a88d8 | 22 | #pragma implementation "listctrlbase.h" |
2bda0e17 KB |
23 | #endif |
24 | ||
25 | // For compilers that support precompilation, includes "wx.h". | |
26 | #include "wx/wxprec.h" | |
27 | ||
28 | #ifdef __BORLANDC__ | |
0b5efdc7 | 29 | #pragma hdrstop |
2bda0e17 KB |
30 | #endif |
31 | ||
98ec9dbe | 32 | #if wxUSE_LISTCTRL && defined(__WIN95__) |
9f303149 | 33 | |
2bda0e17 | 34 | #ifndef WX_PRECOMP |
9f303149 | 35 | #include "wx/app.h" |
9f303149 VZ |
36 | #include "wx/intl.h" |
37 | #include "wx/log.h" | |
38 | #include "wx/settings.h" | |
2bda0e17 KB |
39 | #endif |
40 | ||
de8e98f1 JS |
41 | #include "wx/textctrl.h" |
42 | #include "wx/imaglist.h" | |
2bda0e17 | 43 | #include "wx/listctrl.h" |
68fdcf29 | 44 | #include "wx/dcclient.h" |
2bda0e17 KB |
45 | |
46 | #include "wx/msw/private.h" | |
47 | ||
781a24e8 | 48 | #if defined(__WXWINCE__) && !defined(__HANDHELDPC__) |
80a81a12 JS |
49 | #include <ole2.h> |
50 | #include <shellapi.h> | |
2d36b3d8 JS |
51 | #if _WIN32_WCE < 400 |
52 | #include <aygshell.h> | |
53 | #endif | |
80a81a12 JS |
54 | #endif |
55 | ||
0d236fd0 VZ |
56 | // include <commctrl.h> "properly" |
57 | #include "wx/msw/wrapcctl.h" | |
12979259 | 58 | |
2f73fd38 MW |
59 | // Currently gcc and watcom don't define NMLVFINDITEM, and DMC only defines |
60 | // it by its old name NM_FINDTIEM. | |
61 | // | |
73f91e1e | 62 | #if defined(__VISUALC__) || defined(__BORLANDC__) || defined(NMLVFINDITEM) |
2f73fd38 | 63 | #define HAVE_NMLVFINDITEM 1 |
73f91e1e | 64 | #elif defined(__DMC__) || defined(NM_FINDITEM) |
206391cb VZ |
65 | #define HAVE_NMLVFINDITEM 1 |
66 | #define NMLVFINDITEM NM_FINDITEM | |
2f73fd38 MW |
67 | #endif |
68 | ||
edccf428 VZ |
69 | // ---------------------------------------------------------------------------- |
70 | // private functions | |
71 | // ---------------------------------------------------------------------------- | |
2bda0e17 | 72 | |
8dff2b5c VZ |
73 | // convert our state and mask flags to LV_ITEM constants |
74 | static void wxConvertToMSWFlags(long state, long mask, LV_ITEM& lvItem); | |
75 | ||
76 | // convert wxListItem to LV_ITEM | |
77 | static void wxConvertToMSWListItem(const wxListCtrl *ctrl, | |
78 | const wxListItem& info, LV_ITEM& lvItem); | |
79 | ||
80 | // convert LV_ITEM to wxListItem | |
81 | static void wxConvertFromMSWListItem(HWND hwndListCtrl, | |
82 | wxListItem& info, | |
83 | /* const */ LV_ITEM& lvItem); | |
2bda0e17 | 84 | |
6f806543 VZ |
85 | // convert our wxListItem to LV_COLUMN |
86 | static void wxConvertToMSWListCol(int col, const wxListItem& item, | |
87 | LV_COLUMN& lvCol); | |
88 | ||
8c21905b VS |
89 | // ---------------------------------------------------------------------------- |
90 | // private helper classes | |
91 | // ---------------------------------------------------------------------------- | |
92 | ||
93 | // We have to handle both fooW and fooA notifications in several cases | |
d2ed74b9 | 94 | // because of broken comctl32.dll and/or unicows.dll. This class is used to |
73d8c5fd | 95 | // convert LV_ITEMA and LV_ITEMW to LV_ITEM (which is either LV_ITEMA or |
8c21905b VS |
96 | // LV_ITEMW depending on wxUSE_UNICODE setting), so that it can be processed |
97 | // by wxConvertToMSWListItem(). | |
d2ed74b9 VZ |
98 | #if wxUSE_UNICODE |
99 | #define LV_ITEM_NATIVE LV_ITEMW | |
100 | #define LV_ITEM_OTHER LV_ITEMA | |
101 | ||
102 | #define LV_CONV_TO_WX cMB2WX | |
103 | #define LV_CONV_BUF wxMB2WXbuf | |
104 | #else // ANSI | |
105 | #define LV_ITEM_NATIVE LV_ITEMA | |
106 | #define LV_ITEM_OTHER LV_ITEMW | |
107 | ||
108 | #define LV_CONV_TO_WX cWC2WX | |
109 | #define LV_CONV_BUF wxWC2WXbuf | |
110 | #endif // Unicode/ANSI | |
111 | ||
8c21905b VS |
112 | class wxLV_ITEM |
113 | { | |
114 | public: | |
d2ed74b9 VZ |
115 | // default ctor, use Init() later |
116 | wxLV_ITEM() { m_buf = NULL; m_pItem = NULL; } | |
8c21905b | 117 | |
d2ed74b9 VZ |
118 | // init without conversion |
119 | void Init(LV_ITEM_NATIVE& item) | |
8c21905b | 120 | { |
d2ed74b9 VZ |
121 | wxASSERT_MSG( !m_pItem, _T("Init() called twice?") ); |
122 | ||
123 | m_pItem = &item; | |
73d8c5fd | 124 | } |
8c21905b | 125 | |
d2ed74b9 VZ |
126 | // init with conversion |
127 | void Init(LV_ITEM_OTHER& item) | |
8c21905b | 128 | { |
d2ed74b9 VZ |
129 | // avoid unnecessary dynamic memory allocation, jjust make m_pItem |
130 | // point to our own m_item | |
2b5f62a0 | 131 | |
1c6f2414 WS |
132 | // memcpy() can't work if the struct sizes are different |
133 | wxCOMPILE_TIME_ASSERT( sizeof(LV_ITEM_OTHER) == sizeof(LV_ITEM_NATIVE), | |
134 | CodeCantWorkIfDiffSizes); | |
135 | ||
d2ed74b9 VZ |
136 | memcpy(&m_item, &item, sizeof(LV_ITEM_NATIVE)); |
137 | ||
138 | // convert text from ANSI to Unicod if necessary | |
8c21905b VS |
139 | if ( (item.mask & LVIF_TEXT) && item.pszText ) |
140 | { | |
d2ed74b9 VZ |
141 | m_buf = new LV_CONV_BUF(wxConvLocal.LV_CONV_TO_WX(item.pszText)); |
142 | m_item.pszText = (wxChar *)m_buf->data(); | |
8c21905b | 143 | } |
73d8c5fd | 144 | } |
d2ed74b9 VZ |
145 | |
146 | // ctor without conversion | |
147 | wxLV_ITEM(LV_ITEM_NATIVE& item) : m_buf(NULL), m_pItem(&item) { } | |
148 | ||
149 | // ctor with conversion | |
150 | wxLV_ITEM(LV_ITEM_OTHER& item) : m_buf(NULL) | |
151 | { | |
152 | Init(item); | |
153 | } | |
154 | ||
155 | ~wxLV_ITEM() { delete m_buf; } | |
156 | ||
157 | // conversion to the real LV_ITEM | |
158 | operator LV_ITEM_NATIVE&() const { return *m_pItem; } | |
159 | ||
8c21905b | 160 | private: |
d2ed74b9 | 161 | LV_CONV_BUF *m_buf; |
8c21905b | 162 | |
d2ed74b9 VZ |
163 | LV_ITEM_NATIVE *m_pItem; |
164 | LV_ITEM_NATIVE m_item; | |
22f3361e VZ |
165 | |
166 | DECLARE_NO_COPY_CLASS(wxLV_ITEM) | |
8c21905b VS |
167 | }; |
168 | ||
7cf46fdb VZ |
169 | /////////////////////////////////////////////////////// |
170 | // Problem: | |
73d8c5fd RD |
171 | // The MSW version had problems with SetTextColour() et |
172 | // al as the wxListItemAttr's were stored keyed on the | |
173 | // item index. If a item was inserted anywhere but the end | |
174 | // of the list the the text attributes (colour etc) for | |
7cf46fdb | 175 | // the following items were out of sync. |
73d8c5fd | 176 | // |
7cf46fdb | 177 | // Solution: |
73d8c5fd | 178 | // Under MSW the only way to associate data with a List |
43e8916f | 179 | // item independent of its position in the list is to |
73d8c5fd RD |
180 | // store a pointer to it in its lParam attribute. However |
181 | // user programs are already using this (via the | |
7cf46fdb | 182 | // SetItemData() GetItemData() calls). |
73d8c5fd RD |
183 | // |
184 | // However what we can do is store a pointer to a | |
185 | // structure which contains the attributes we want *and* | |
7cf46fdb | 186 | // a lParam for the users data, e.g. |
73d8c5fd | 187 | // |
7cf46fdb VZ |
188 | // class wxListItemInternalData |
189 | // { | |
190 | // public: | |
73d8c5fd | 191 | // wxListItemAttr *attr; |
7cf46fdb VZ |
192 | // long lParam; // user data |
193 | // }; | |
73d8c5fd RD |
194 | // |
195 | // To conserve memory, a wxListItemInternalData is | |
196 | // only allocated for a LV_ITEM if text attributes or | |
7cf46fdb VZ |
197 | // user data(lparam) are being set. |
198 | ||
199 | ||
200 | // class wxListItemInternalData | |
201 | class wxListItemInternalData | |
202 | { | |
203 | public: | |
73d8c5fd | 204 | wxListItemAttr *attr; |
7cf46fdb VZ |
205 | LPARAM lParam; // user data |
206 | ||
207 | wxListItemInternalData() : attr(NULL), lParam(0) {} | |
208 | ~wxListItemInternalData() | |
209 | { | |
210 | if (attr) | |
211 | delete attr; | |
212 | }; | |
22f3361e VZ |
213 | |
214 | DECLARE_NO_COPY_CLASS(wxListItemInternalData) | |
7cf46fdb VZ |
215 | }; |
216 | ||
217 | // Get the internal data structure | |
6149de71 | 218 | static wxListItemInternalData *wxGetInternalData(HWND hwnd, long itemId); |
97c611f8 | 219 | static wxListItemInternalData *wxGetInternalData(const wxListCtrl *ctl, long itemId); |
6149de71 RD |
220 | static wxListItemAttr *wxGetInternalDataAttr(wxListCtrl *ctl, long itemId); |
221 | static void wxDeleteInternalData(wxListCtrl* ctl, long itemId); | |
7cf46fdb VZ |
222 | |
223 | ||
edccf428 | 224 | // ---------------------------------------------------------------------------- |
2e4df4bf | 225 | // events |
edccf428 VZ |
226 | // ---------------------------------------------------------------------------- |
227 | ||
2e4df4bf VZ |
228 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG) |
229 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG) | |
230 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT) | |
231 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT) | |
232 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM) | |
233 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS) | |
c3627a00 | 234 | #if WXWIN_COMPATIBILITY_2_4 |
2e4df4bf VZ |
235 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO) |
236 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO) | |
c3627a00 | 237 | #endif |
2e4df4bf VZ |
238 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED) |
239 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED) | |
240 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN) | |
241 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM) | |
242 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK) | |
11358d39 VZ |
243 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_RIGHT_CLICK) |
244 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG) | |
245 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_DRAGGING) | |
246 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_END_DRAG) | |
2e4df4bf VZ |
247 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK) |
248 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK) | |
249 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED) | |
0ddefeb0 | 250 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_FOCUSED) |
614391dc | 251 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT) |
2e4df4bf | 252 | |
786a2425 | 253 | #if wxUSE_EXTENDED_RTTI |
bc9fb572 JS |
254 | WX_DEFINE_FLAGS( wxListCtrlStyle ) |
255 | ||
321239b6 | 256 | wxBEGIN_FLAGS( wxListCtrlStyle ) |
bc9fb572 JS |
257 | // new style border flags, we put them first to |
258 | // use them for streaming out | |
321239b6 SC |
259 | wxFLAGS_MEMBER(wxBORDER_SIMPLE) |
260 | wxFLAGS_MEMBER(wxBORDER_SUNKEN) | |
261 | wxFLAGS_MEMBER(wxBORDER_DOUBLE) | |
262 | wxFLAGS_MEMBER(wxBORDER_RAISED) | |
263 | wxFLAGS_MEMBER(wxBORDER_STATIC) | |
264 | wxFLAGS_MEMBER(wxBORDER_NONE) | |
598ddd96 | 265 | |
bc9fb572 | 266 | // old style border flags |
321239b6 SC |
267 | wxFLAGS_MEMBER(wxSIMPLE_BORDER) |
268 | wxFLAGS_MEMBER(wxSUNKEN_BORDER) | |
269 | wxFLAGS_MEMBER(wxDOUBLE_BORDER) | |
270 | wxFLAGS_MEMBER(wxRAISED_BORDER) | |
271 | wxFLAGS_MEMBER(wxSTATIC_BORDER) | |
cb0afb26 | 272 | wxFLAGS_MEMBER(wxBORDER) |
bc9fb572 JS |
273 | |
274 | // standard window styles | |
321239b6 SC |
275 | wxFLAGS_MEMBER(wxTAB_TRAVERSAL) |
276 | wxFLAGS_MEMBER(wxCLIP_CHILDREN) | |
277 | wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW) | |
278 | wxFLAGS_MEMBER(wxWANTS_CHARS) | |
cb0afb26 | 279 | wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE) |
321239b6 SC |
280 | wxFLAGS_MEMBER(wxALWAYS_SHOW_SB ) |
281 | wxFLAGS_MEMBER(wxVSCROLL) | |
282 | wxFLAGS_MEMBER(wxHSCROLL) | |
283 | ||
284 | wxFLAGS_MEMBER(wxLC_LIST) | |
285 | wxFLAGS_MEMBER(wxLC_REPORT) | |
286 | wxFLAGS_MEMBER(wxLC_ICON) | |
287 | wxFLAGS_MEMBER(wxLC_SMALL_ICON) | |
288 | wxFLAGS_MEMBER(wxLC_ALIGN_TOP) | |
289 | wxFLAGS_MEMBER(wxLC_ALIGN_LEFT) | |
290 | wxFLAGS_MEMBER(wxLC_AUTOARRANGE) | |
291 | wxFLAGS_MEMBER(wxLC_USER_TEXT) | |
292 | wxFLAGS_MEMBER(wxLC_EDIT_LABELS) | |
293 | wxFLAGS_MEMBER(wxLC_NO_HEADER) | |
294 | wxFLAGS_MEMBER(wxLC_SINGLE_SEL) | |
295 | wxFLAGS_MEMBER(wxLC_SORT_ASCENDING) | |
296 | wxFLAGS_MEMBER(wxLC_SORT_DESCENDING) | |
297 | wxFLAGS_MEMBER(wxLC_VIRTUAL) | |
298 | ||
299 | wxEND_FLAGS( wxListCtrlStyle ) | |
bc9fb572 | 300 | |
786a2425 SC |
301 | IMPLEMENT_DYNAMIC_CLASS_XTI(wxListCtrl, wxControl,"wx/listctrl.h") |
302 | ||
321239b6 | 303 | wxBEGIN_PROPERTIES_TABLE(wxListCtrl) |
598ddd96 | 304 | wxEVENT_PROPERTY( TextUpdated , wxEVT_COMMAND_TEXT_UPDATED , wxCommandEvent ) |
c5ca409b | 305 | |
af498247 | 306 | wxPROPERTY_FLAGS( WindowStyle , wxListCtrlStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style |
321239b6 | 307 | wxEND_PROPERTIES_TABLE() |
786a2425 | 308 | |
321239b6 SC |
309 | wxBEGIN_HANDLERS_TABLE(wxListCtrl) |
310 | wxEND_HANDLERS_TABLE() | |
786a2425 | 311 | |
598ddd96 | 312 | wxCONSTRUCTOR_5( wxListCtrl , wxWindow* , Parent , wxWindowID , Id , wxPoint , Position , wxSize , Size , long , WindowStyle ) |
786a2425 SC |
313 | |
314 | /* | |
315 | Content-type: text/html ]>