]>
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$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
acb62b84 | 9 | // Licence: wxWindows license |
2bda0e17 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
edccf428 VZ |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
2bda0e17 | 20 | #ifdef __GNUG__ |
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 | ||
ae090fdb | 48 | #if ((defined(__GNUWIN32_OLD__) || defined(__TWIN32__)) && !defined(__CYGWIN10__)) |
edccf428 VZ |
49 | #include "wx/msw/gnuwin32/extra.h" |
50 | #else | |
0b5efdc7 | 51 | #include <commctrl.h> |
2bda0e17 KB |
52 | #endif |
53 | ||
7391216e | 54 | #include "wx/msw/missing.h" |
12979259 | 55 | |
edccf428 VZ |
56 | // ---------------------------------------------------------------------------- |
57 | // private functions | |
58 | // ---------------------------------------------------------------------------- | |
2bda0e17 | 59 | |
8dff2b5c VZ |
60 | // convert our state and mask flags to LV_ITEM constants |
61 | static void wxConvertToMSWFlags(long state, long mask, LV_ITEM& lvItem); | |
62 | ||
63 | // convert wxListItem to LV_ITEM | |
64 | static void wxConvertToMSWListItem(const wxListCtrl *ctrl, | |
65 | const wxListItem& info, LV_ITEM& lvItem); | |
66 | ||
67 | // convert LV_ITEM to wxListItem | |
68 | static void wxConvertFromMSWListItem(HWND hwndListCtrl, | |
69 | wxListItem& info, | |
70 | /* const */ LV_ITEM& lvItem); | |
2bda0e17 | 71 | |
6f806543 VZ |
72 | // convert our wxListItem to LV_COLUMN |
73 | static void wxConvertToMSWListCol(int col, const wxListItem& item, | |
74 | LV_COLUMN& lvCol); | |
75 | ||
8c21905b VS |
76 | // ---------------------------------------------------------------------------- |
77 | // private helper classes | |
78 | // ---------------------------------------------------------------------------- | |
79 | ||
80 | // We have to handle both fooW and fooA notifications in several cases | |
81 | // because of broken commctl.dll and/or unicows.dll. This class is used to | |
73d8c5fd | 82 | // convert LV_ITEMA and LV_ITEMW to LV_ITEM (which is either LV_ITEMA or |
8c21905b VS |
83 | // LV_ITEMW depending on wxUSE_UNICODE setting), so that it can be processed |
84 | // by wxConvertToMSWListItem(). | |
85 | class wxLV_ITEM | |
86 | { | |
87 | public: | |
88 | ~wxLV_ITEM() { delete m_buf; } | |
89 | operator LV_ITEM&() const { return *m_item; } | |
90 | ||
91 | #if wxUSE_UNICODE | |
92 | wxLV_ITEM(LV_ITEMW &item) : m_buf(NULL), m_item(&item) {} | |
93 | wxLV_ITEM(LV_ITEMA &item) | |
94 | { | |
95 | m_item = new LV_ITEM((LV_ITEM&)item); | |
96 | if ( (item.mask & LVIF_TEXT) && item.pszText ) | |
97 | { | |
98 | m_buf = new wxMB2WXbuf(wxConvLocal.cMB2WX(item.pszText)); | |
99 | m_item->pszText = (wxChar*)m_buf->data(); | |
100 | } | |
101 | else | |
102 | m_buf = NULL; | |
73d8c5fd | 103 | } |
8c21905b VS |
104 | private: |
105 | wxMB2WXbuf *m_buf; | |
106 | ||
2b5f62a0 | 107 | #else // !wxUSE_UNICODE |
8c21905b VS |
108 | wxLV_ITEM(LV_ITEMW &item) |
109 | { | |
110 | m_item = new LV_ITEM((LV_ITEM&)item); | |
2b5f62a0 VZ |
111 | |
112 | // the code below doesn't compile without wxUSE_WCHAR_T and as I don't | |
113 | // know if it's useful to have it at all (do we ever get Unicode | |
114 | // notifications in ANSI mode? I don't think so...) I'm not going to | |
115 | // write alternative implementation right now | |
116 | // | |
117 | // but if it is indeed used, we should simply directly use | |
118 | // ::WideCharToMultiByte() here | |
119 | #if wxUSE_WCHAR_T | |
8c21905b VS |
120 | if ( (item.mask & LVIF_TEXT) && item.pszText ) |
121 | { | |
3bce6687 JS |
122 | #ifdef __WXWINE__ |
123 | // FIXME | |
124 | m_buf = new wxWC2WXbuf(wxConvLocal.cWC2WX((const __wchar_t* ) item.pszText)); | |
125 | #else | |
8c21905b | 126 | m_buf = new wxWC2WXbuf(wxConvLocal.cWC2WX(item.pszText)); |
3bce6687 | 127 | #endif |
8c21905b VS |
128 | m_item->pszText = (wxChar*)m_buf->data(); |
129 | } | |
130 | else | |
2b5f62a0 | 131 | #endif // wxUSE_WCHAR_T |
8c21905b | 132 | m_buf = NULL; |
73d8c5fd | 133 | } |
8c21905b VS |
134 | wxLV_ITEM(LV_ITEMA &item) : m_buf(NULL), m_item(&item) {} |
135 | private: | |
136 | wxWC2WXbuf *m_buf; | |
2b5f62a0 | 137 | #endif // wxUSE_UNICODE/!wxUSE_UNICODE |
8c21905b VS |
138 | |
139 | LV_ITEM *m_item; | |
140 | }; | |
141 | ||
7cf46fdb VZ |
142 | /////////////////////////////////////////////////////// |
143 | // Problem: | |
73d8c5fd RD |
144 | // The MSW version had problems with SetTextColour() et |
145 | // al as the wxListItemAttr's were stored keyed on the | |
146 | // item index. If a item was inserted anywhere but the end | |
147 | // of the list the the text attributes (colour etc) for | |
7cf46fdb | 148 | // the following items were out of sync. |
73d8c5fd | 149 | // |
7cf46fdb | 150 | // Solution: |
73d8c5fd RD |
151 | // Under MSW the only way to associate data with a List |
152 | // item independant of its position in the list is to | |
153 | // store a pointer to it in its lParam attribute. However | |
154 | // user programs are already using this (via the | |
7cf46fdb | 155 | // SetItemData() GetItemData() calls). |
73d8c5fd RD |
156 | // |
157 | // However what we can do is store a pointer to a | |
158 | // structure which contains the attributes we want *and* | |
7cf46fdb | 159 | // a lParam for the users data, e.g. |
73d8c5fd | 160 | // |
7cf46fdb VZ |
161 | // class wxListItemInternalData |
162 | // { | |
163 | // public: | |
73d8c5fd | 164 | // wxListItemAttr *attr; |
7cf46fdb VZ |
165 | // long lParam; // user data |
166 | // }; | |
73d8c5fd RD |
167 | // |
168 | // To conserve memory, a wxListItemInternalData is | |
169 | // only allocated for a LV_ITEM if text attributes or | |
7cf46fdb VZ |
170 | // user data(lparam) are being set. |
171 | ||
172 | ||
173 | // class wxListItemInternalData | |
174 | class wxListItemInternalData | |
175 | { | |
176 | public: | |
73d8c5fd | 177 | wxListItemAttr *attr; |
7cf46fdb VZ |
178 | LPARAM lParam; // user data |
179 | ||
180 | wxListItemInternalData() : attr(NULL), lParam(0) {} | |
181 | ~wxListItemInternalData() | |
182 | { | |
183 | if (attr) | |
184 | delete attr; | |
185 | }; | |
186 | }; | |
187 | ||
188 | // Get the internal data structure | |
6149de71 RD |
189 | static wxListItemInternalData *wxGetInternalData(HWND hwnd, long itemId); |
190 | static wxListItemInternalData *wxGetInternalData(wxListCtrl *ctl, long itemId); | |
191 | static wxListItemAttr *wxGetInternalDataAttr(wxListCtrl *ctl, long itemId); | |
192 | static void wxDeleteInternalData(wxListCtrl* ctl, long itemId); | |
7cf46fdb VZ |
193 | |
194 | ||
edccf428 | 195 | // ---------------------------------------------------------------------------- |
2e4df4bf | 196 | // events |
edccf428 VZ |
197 | // ---------------------------------------------------------------------------- |
198 | ||
2e4df4bf VZ |
199 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG) |
200 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG) | |
201 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT) | |
202 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT) | |
203 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM) | |
204 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS) | |
205 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO) | |
206 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO) | |
207 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED) | |
208 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED) | |
209 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN) | |
210 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM) | |
211 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK) | |
11358d39 VZ |
212 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_RIGHT_CLICK) |
213 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG) | |
214 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_DRAGGING) | |
215 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_END_DRAG) | |
2e4df4bf VZ |
216 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK) |
217 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK) | |
218 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED) | |
0ddefeb0 | 219 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_FOCUSED) |
614391dc | 220 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT) |
2e4df4bf | 221 | |
8f177c8e | 222 | IMPLEMENT_DYNAMIC_CLASS(wxListCtrl, wxControl) |
bf9b6266 | 223 | IMPLEMENT_DYNAMIC_CLASS(wxListView, wxListCtrl) |
8f177c8e | 224 | IMPLEMENT_DYNAMIC_CLASS(wxListItem, wxObject) |
2bda0e17 | 225 | |
2d33aec9 VZ |
226 | IMPLEMENT_DYNAMIC_CLASS(wxListEvent, wxNotifyEvent) |
227 | ||
2702ed5a JS |
228 | BEGIN_EVENT_TABLE(wxListCtrl, wxControl) |
229 | EVT_PAINT(wxListCtrl::OnPaint) | |
230 | END_EVENT_TABLE() | |
231 | ||
edccf428 VZ |
232 | // ============================================================================ |
233 | // implementation | |
234 | // ============================================================================ | |
235 | ||
236 | // ---------------------------------------------------------------------------- | |
237 | // wxListCtrl construction | |
238 | // ---------------------------------------------------------------------------- | |
239 | ||
bdc72a22 | 240 | void wxListCtrl::Init() |
2bda0e17 | 241 | { |
0b5efdc7 VZ |
242 | m_imageListNormal = NULL; |
243 | m_imageListSmall = NULL; | |
244 | m_imageListState = NULL; | |
2e12c11a | 245 | m_ownsImageListNormal = m_ownsImageListSmall = m_ownsImageListState = FALSE; |
0b5efdc7 | 246 | m_baseStyle = 0; |
2bda0e17 | 247 | m_colCount = 0; |
bbcdf8bc | 248 | m_textCtrl = NULL; |
7cf46fdb | 249 | m_AnyInternalData = FALSE; |
bdc72a22 | 250 | m_hasAnyAttr = FALSE; |
2bda0e17 KB |
251 | } |
252 | ||
0b5efdc7 VZ |
253 | bool wxListCtrl::Create(wxWindow *parent, |
254 | wxWindowID id, | |
255 | const wxPoint& pos, | |
256 | const wxSize& size, | |
257 | long style, | |
258 | const wxValidator& validator, | |
259 | const wxString& name) | |
2bda0e17 | 260 | { |
11b6a93b | 261 | #if wxUSE_VALIDATORS |
0b5efdc7 | 262 | SetValidator(validator); |
11b6a93b VZ |
263 | #endif // wxUSE_VALIDATORS |
264 | ||
0b5efdc7 | 265 | SetName(name); |
2bda0e17 | 266 | |
0b5efdc7 VZ |
267 | int x = pos.x; |
268 | int y = pos.y; | |
269 | int width = size.x; | |
270 | int height = size.y; | |
2bda0e17 | 271 | |
0b5efdc7 | 272 | m_windowStyle = style; |
2bda0e17 | 273 | |
0b5efdc7 | 274 | SetParent(parent); |
2bda0e17 | 275 | |
0b5efdc7 VZ |
276 | if (width <= 0) |
277 | width = 100; | |
278 | if (height <= 0) | |
279 | height = 30; | |
280 | if (x < 0) | |
281 | x = 0; | |
282 | if (y < 0) | |
283 | y = 0; | |
2bda0e17 | 284 | |
0b5efdc7 | 285 | m_windowId = (id == -1) ? NewControlId() : id; |
2bda0e17 | 286 | |
edccf428 VZ |
287 | DWORD wstyle = WS_VISIBLE | WS_CHILD | WS_TABSTOP | |
288 | LVS_SHAREIMAGELISTS | LVS_SHOWSELALWAYS; | |
b0766406 JS |
289 | |
290 | if ( m_windowStyle & wxCLIP_SIBLINGS ) | |
291 | wstyle |= WS_CLIPSIBLINGS; | |
292 | ||
edccf428 VZ |
293 | if ( wxStyleHasBorder(m_windowStyle) ) |
294 | wstyle |= WS_BORDER; | |
295 | m_baseStyle = wstyle; | |
296 | ||
297 | if ( !DoCreateControl(x, y, width, height) ) | |
298 | return FALSE; | |
299 | ||
300 | if (parent) | |
301 | parent->AddChild(this); | |
302 | ||
303 | return TRUE; | |
304 | } | |
305 | ||
306 | bool wxListCtrl::DoCreateControl(int x, int y, int w, int h) | |
307 | { | |
308 | DWORD wstyle = m_baseStyle; | |
2bda0e17 | 309 | |
0b5efdc7 | 310 | bool want3D; |
edccf428 | 311 | WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, &want3D); |
2bda0e17 | 312 | |
0b5efdc7 VZ |
313 | // Even with extended styles, need to combine with WS_BORDER |
314 | // for them to look right. | |
edccf428 | 315 | if ( want3D ) |
0b5efdc7 | 316 | wstyle |= WS_BORDER; |
2bda0e17 | 317 | |
0b5efdc7 VZ |
318 | long oldStyle = 0; // Dummy |
319 | wstyle |= ConvertToMSWStyle(oldStyle, m_windowStyle); | |
2bda0e17 | 320 | |
0b5efdc7 VZ |
321 | // Create the ListView control. |
322 | m_hWnd = (WXHWND)CreateWindowEx(exStyle, | |
323 | WC_LISTVIEW, | |
223d09f6 | 324 | wxT(""), |
0b5efdc7 | 325 | wstyle, |
edccf428 VZ |
326 | x, y, w, h, |
327 | GetWinHwnd(GetParent()), | |
0b5efdc7 VZ |
328 | (HMENU)m_windowId, |
329 | wxGetInstance(), | |
330 | NULL); | |
f8352807 | 331 | |
edccf428 VZ |
332 | if ( !m_hWnd ) |
333 | { | |
f6bcfd97 | 334 | wxLogError(_("Can't create list control window, check that comctl32.dll is installed.")); |
0b5efdc7 VZ |
335 | |
336 | return FALSE; | |
337 | } | |
338 | ||
339 | // for comctl32.dll v 4.70+ we want to have this attribute because it's | |
340 | // prettier (and also because wxGTK does it like this) | |
225fe9d6 | 341 | if ( (wstyle & LVS_REPORT) && wxTheApp->GetComCtl32Version() >= 470 ) |
0b5efdc7 | 342 | { |
225fe9d6 VZ |
343 | ::SendMessage(GetHwnd(), LVM_SETEXTENDEDLISTVIEWSTYLE, |
344 | 0, LVS_EX_FULLROWSELECT); | |
0b5efdc7 | 345 | } |
f8352807 | 346 | |
a756f210 | 347 | SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); |
edccf428 | 348 | SetForegroundColour(GetParent()->GetForegroundColour()); |
2bda0e17 | 349 | |
edccf428 | 350 | SubclassWin(m_hWnd); |
2bda0e17 | 351 | |
0b5efdc7 | 352 | return TRUE; |
2bda0e17 KB |
353 | } |
354 | ||
edccf428 VZ |
355 | void wxListCtrl::UpdateStyle() |
356 | { | |
357 | if ( GetHWND() ) | |
358 | { | |
359 | // The new window view style | |
360 | long dummy; | |
361 | DWORD dwStyleNew = ConvertToMSWStyle(dummy, m_windowStyle); | |
362 | dwStyleNew |= m_baseStyle; | |
363 | ||
910484a6 | 364 | // Get the current window style. |
edccf428 VZ |
365 | DWORD dwStyleOld = ::GetWindowLong(GetHwnd(), GWL_STYLE); |
366 | ||
910484a6 | 367 | // Only set the window style if the view bits have changed. |
edccf428 VZ |
368 | if ( dwStyleOld != dwStyleNew ) |
369 | { | |
370 | ::SetWindowLong(GetHwnd(), GWL_STYLE, dwStyleNew); | |
371 | } | |
372 | } | |
373 | } | |
374 | ||
7cf46fdb | 375 | void wxListCtrl::FreeAllInternalData() |
2bda0e17 | 376 | { |
7cf46fdb | 377 | if (m_AnyInternalData) |
73d8c5fd | 378 | { |
7cf46fdb VZ |
379 | int n = GetItemCount(); |
380 | int i = 0; | |
6932a32c | 381 | |
7cf46fdb | 382 | for (i = 0; i < n; i++) |
6149de71 RD |
383 | wxDeleteInternalData(this, i); |
384 | ||
73d8c5fd RD |
385 | m_AnyInternalData = FALSE; |
386 | } | |
6932a32c | 387 | } |
d62228a6 | 388 | |
6932a32c VZ |
389 | wxListCtrl::~wxListCtrl() |
390 | { | |
7cf46fdb | 391 | FreeAllInternalData(); |
91b4c08d | 392 | |
d62228a6 | 393 | if ( m_textCtrl ) |
bbcdf8bc | 394 | { |
0b5efdc7 | 395 | m_textCtrl->SetHWND(0); |
7bf1474a | 396 | m_textCtrl->UnsubclassWin(); |
0b5efdc7 VZ |
397 | delete m_textCtrl; |
398 | m_textCtrl = NULL; | |
bbcdf8bc | 399 | } |
33ac7e6f | 400 | |
2e12c11a VS |
401 | if (m_ownsImageListNormal) delete m_imageListNormal; |
402 | if (m_ownsImageListSmall) delete m_imageListSmall; | |
403 | if (m_ownsImageListState) delete m_imageListState; | |
2bda0e17 KB |
404 | } |
405 | ||
edccf428 VZ |
406 | // ---------------------------------------------------------------------------- |
407 | // set/get/change style | |
408 | // ---------------------------------------------------------------------------- | |
409 | ||
2bda0e17 | 410 | // Add or remove a single window style |
debe6624 | 411 | void wxListCtrl::SetSingleStyle(long style, bool add) |
2bda0e17 | 412 | { |
0b5efdc7 | 413 | long flag = GetWindowStyleFlag(); |
2bda0e17 | 414 | |
0b5efdc7 | 415 | // Get rid of conflicting styles |
acb62b84 VZ |
416 | if ( add ) |
417 | { | |
0b5efdc7 | 418 | if ( style & wxLC_MASK_TYPE) |
edccf428 | 419 | flag = flag & ~wxLC_MASK_TYPE; |
0b5efdc7 | 420 | if ( style & wxLC_MASK_ALIGN ) |
edccf428 | 421 | flag = flag & ~wxLC_MASK_ALIGN; |
0b5efdc7 | 422 | if ( style & wxLC_MASK_SORT ) |
edccf428 | 423 | flag = flag & ~wxLC_MASK_SORT; |
acb62b84 | 424 | } |
2bda0e17 | 425 | |
0b5efdc7 VZ |
426 | if ( flag & style ) |
427 | { | |
428 | if ( !add ) | |
429 | flag -= style; | |
430 | } | |
431 | else | |
432 | { | |
433 | if ( add ) | |
434 | { | |
435 | flag |= style; | |
436 | } | |
437 | } | |
438 | ||
439 | m_windowStyle = flag; | |
2bda0e17 | 440 | |
edccf428 | 441 | UpdateStyle(); |
2bda0e17 KB |
442 | } |
443 | ||
444 | // Set the whole window style | |
debe6624 | 445 | void wxListCtrl::SetWindowStyleFlag(long flag) |
2bda0e17 | 446 | { |
0b5efdc7 | 447 | m_windowStyle = flag; |
2bda0e17 | 448 | |
edccf428 | 449 | UpdateStyle(); |
2bda0e17 KB |
450 | } |
451 | ||
0b5efdc7 VZ |
452 | // Can be just a single style, or a bitlist |
453 | long wxListCtrl::ConvertToMSWStyle(long& oldStyle, long style) const | |
2bda0e17 | 454 | { |
0b5efdc7 VZ |
455 | long wstyle = 0; |
456 | if ( style & wxLC_ICON ) | |
457 | { | |
458 | if ( (oldStyle & LVS_TYPEMASK) == LVS_SMALLICON ) | |
459 | oldStyle -= LVS_SMALLICON; | |
460 | if ( (oldStyle & LVS_TYPEMASK) == LVS_REPORT ) | |
461 | oldStyle -= LVS_REPORT; | |
462 | if ( (oldStyle & LVS_TYPEMASK) == LVS_LIST ) | |
463 | oldStyle -= LVS_LIST; | |
464 | wstyle |= LVS_ICON; | |
465 | } | |
466 | ||
467 | if ( style & wxLC_SMALL_ICON ) | |
468 | { | |
469 | if ( (oldStyle & LVS_TYPEMASK) == LVS_ICON ) | |
470 | oldStyle -= LVS_ICON; | |
471 | if ( (oldStyle & LVS_TYPEMASK) == LVS_REPORT ) | |
472 | oldStyle -= LVS_REPORT; | |
473 | if ( (oldStyle & LVS_TYPEMASK) == LVS_LIST ) | |
474 | oldStyle -= LVS_LIST; | |
475 | wstyle |= LVS_SMALLICON; | |
476 | } | |
477 | ||
478 | if ( style & wxLC_LIST ) | |
479 | { | |
480 | if ( (oldStyle & LVS_TYPEMASK) == LVS_ICON ) | |
481 | oldStyle -= LVS_ICON; | |
482 | if ( (oldStyle & LVS_TYPEMASK) == LVS_REPORT ) | |
483 | oldStyle -= LVS_REPORT; | |
484 | if ( (oldStyle & LVS_TYPEMASK) == LVS_SMALLICON ) | |
485 | oldStyle -= LVS_SMALLICON; | |
486 | wstyle |= LVS_LIST; | |
487 | } | |
2bda0e17 | 488 | |
0b5efdc7 VZ |
489 | if ( style & wxLC_REPORT ) |
490 | { | |
491 | if ( (oldStyle & LVS_TYPEMASK) == LVS_ICON ) | |
492 | oldStyle -= LVS_ICON; | |
493 | if ( (oldStyle & LVS_TYPEMASK) == LVS_LIST ) | |
494 | oldStyle -= LVS_LIST; | |
495 | if ( (oldStyle & LVS_TYPEMASK) == LVS_SMALLICON ) | |
496 | oldStyle -= LVS_SMALLICON; | |
497 | ||
498 | wstyle |= LVS_REPORT; | |
499 | } | |
2bda0e17 | 500 | |
0b5efdc7 VZ |
501 | if ( style & wxLC_ALIGN_LEFT ) |
502 | { | |
503 | if ( oldStyle & LVS_ALIGNTOP ) | |
504 | oldStyle -= LVS_ALIGNTOP; | |
505 | wstyle |= LVS_ALIGNLEFT; | |
506 | } | |
2bda0e17 | 507 | |
0b5efdc7 VZ |
508 | if ( style & wxLC_ALIGN_TOP ) |
509 | { | |
510 | if ( oldStyle & LVS_ALIGNLEFT ) | |
511 | oldStyle -= LVS_ALIGNLEFT; | |
512 | wstyle |= LVS_ALIGNTOP; | |
513 | } | |
2bda0e17 | 514 | |
0b5efdc7 VZ |
515 | if ( style & wxLC_AUTOARRANGE ) |
516 | wstyle |= LVS_AUTOARRANGE; | |
2bda0e17 | 517 | |
0b5efdc7 VZ |
518 | if ( style & wxLC_NO_SORT_HEADER ) |
519 | wstyle |= LVS_NOSORTHEADER; | |
2bda0e17 | 520 | |
0b5efdc7 VZ |
521 | if ( style & wxLC_NO_HEADER ) |
522 | wstyle |= LVS_NOCOLUMNHEADER; | |
523 | ||
524 | if ( style & wxLC_EDIT_LABELS ) | |
525 | wstyle |= LVS_EDITLABELS; | |
526 | ||
527 | if ( style & wxLC_SINGLE_SEL ) | |
528 | wstyle |= LVS_SINGLESEL; | |
529 | ||
530 | if ( style & wxLC_SORT_ASCENDING ) | |
531 | { | |
532 | if ( oldStyle & LVS_SORTDESCENDING ) | |
533 | oldStyle -= LVS_SORTDESCENDING; | |
534 | wstyle |= LVS_SORTASCENDING; | |
535 | } | |
536 | ||
537 | if ( style & wxLC_SORT_DESCENDING ) | |
538 | { | |
539 | if ( oldStyle & LVS_SORTASCENDING ) | |
540 | oldStyle -= LVS_SORTASCENDING; | |
541 | wstyle |= LVS_SORTDESCENDING; | |
542 | } | |
543 | ||
bf9b6266 | 544 | #if !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 0 ) ) |
98ec9dbe VZ |
545 | if ( style & wxLC_VIRTUAL ) |
546 | { | |
30a72e62 VZ |
547 | int ver = wxTheApp->GetComCtl32Version(); |
548 | if ( ver < 470 ) | |
549 | { | |
bf9b6266 | 550 | wxLogWarning(_("Please install a newer version of comctl32.dll\n(at least version 4.70 is required but you have %d.%02d)\nor this program won't operate correctly."), |
30a72e62 VZ |
551 | ver / 100, ver % 100); |
552 | } | |
553 | ||
98ec9dbe VZ |
554 | wstyle |= LVS_OWNERDATA; |
555 | } | |
bf9b6266 | 556 | #endif |
98ec9dbe | 557 | |
0b5efdc7 | 558 | return wstyle; |
2bda0e17 KB |
559 | } |
560 | ||
edccf428 VZ |
561 | // ---------------------------------------------------------------------------- |
562 | // accessors | |
563 | // ---------------------------------------------------------------------------- | |
564 | ||
91b4c08d VZ |
565 | // Sets the foreground, i.e. text, colour |
566 | bool wxListCtrl::SetForegroundColour(const wxColour& col) | |
567 | { | |
568 | if ( !wxWindow::SetForegroundColour(col) ) | |
569 | return FALSE; | |
570 | ||
571 | ListView_SetTextColor(GetHwnd(), wxColourToRGB(col)); | |
572 | ||
573 | return TRUE; | |
574 | } | |
575 | ||
576 | // Sets the background colour | |
cc2b7472 | 577 | bool wxListCtrl::SetBackgroundColour(const wxColour& col) |
2bda0e17 | 578 | { |
cc2b7472 VZ |
579 | if ( !wxWindow::SetBackgroundColour(col) ) |
580 | return FALSE; | |
2bda0e17 | 581 | |
91b4c08d VZ |
582 | // we set the same colour for both the "empty" background and the items |
583 | // background | |
584 | COLORREF color = wxColourToRGB(col); | |
585 | ListView_SetBkColor(GetHwnd(), color); | |
586 | ListView_SetTextBkColor(GetHwnd(), color); | |
cc2b7472 VZ |
587 | |
588 | return TRUE; | |
2bda0e17 KB |
589 | } |
590 | ||
591 | // Gets information about this column | |
debe6624 | 592 | bool wxListCtrl::GetColumn(int col, wxListItem& item) const |
2bda0e17 | 593 | { |
0b5efdc7 | 594 | LV_COLUMN lvCol; |
6f806543 | 595 | wxZeroMemory(lvCol); |
0b5efdc7 | 596 | |
37094564 RD |
597 | lvCol.mask = LVCF_WIDTH; |
598 | ||
0b5efdc7 VZ |
599 | if ( item.m_mask & wxLIST_MASK_TEXT ) |
600 | { | |
601 | lvCol.mask |= LVCF_TEXT; | |
837e5743 | 602 | lvCol.pszText = new wxChar[513]; |
0b5efdc7 VZ |
603 | lvCol.cchTextMax = 512; |
604 | } | |
605 | ||
37094564 RD |
606 | if ( item.m_mask & wxLIST_MASK_FORMAT ) |
607 | { | |
608 | lvCol.mask |= LVCF_FMT; | |
609 | } | |
610 | ||
611 | if ( item.m_mask & wxLIST_MASK_IMAGE ) | |
612 | { | |
613 | lvCol.mask |= LVCF_IMAGE; | |
614 | } | |
615 | ||
0b190ffc | 616 | bool success = ListView_GetColumn(GetHwnd(), col, &lvCol) != 0; |
0b5efdc7 VZ |
617 | |
618 | // item.m_subItem = lvCol.iSubItem; | |
619 | item.m_width = lvCol.cx; | |
620 | ||
621 | if ( (item.m_mask & wxLIST_MASK_TEXT) && lvCol.pszText ) | |
622 | { | |
623 | item.m_text = lvCol.pszText; | |
624 | delete[] lvCol.pszText; | |
625 | } | |
626 | ||
627 | if ( item.m_mask & wxLIST_MASK_FORMAT ) | |
628 | { | |
0b190ffc RD |
629 | switch (lvCol.fmt & LVCFMT_JUSTIFYMASK) { |
630 | case LVCFMT_LEFT: | |
631 | item.m_format = wxLIST_FORMAT_LEFT; | |
632 | break; | |
633 | case LVCFMT_RIGHT: | |
634 | item.m_format = wxLIST_FORMAT_RIGHT; | |
635 | break; | |
636 | case LVCFMT_CENTER: | |
637 | item.m_format = wxLIST_FORMAT_CENTRE; | |
638 | break; | |
639 | default: | |
640 | item.m_format = -1; // Unknown? | |
641 | break; | |
642 | } | |
2bda0e17 KB |
643 | } |
644 | ||
8ac67aa1 | 645 | #if _WIN32_IE >= 0x0300 |
37094564 RD |
646 | if ( item.m_mask & wxLIST_MASK_IMAGE ) |
647 | { | |
648 | item.m_image = lvCol.iImage; | |
649 | } | |
8ac67aa1 | 650 | #endif |
37094564 | 651 | |
0b5efdc7 | 652 | return success; |
2bda0e17 KB |
653 | } |
654 | ||
655 | // Sets information about this column | |
debe6624 | 656 | bool wxListCtrl::SetColumn(int col, wxListItem& item) |
2bda0e17 | 657 | { |
0b5efdc7 | 658 | LV_COLUMN lvCol; |
6f806543 | 659 | wxConvertToMSWListCol(col, item, lvCol); |
0b5efdc7 | 660 | |
6f806543 | 661 | return ListView_SetColumn(GetHwnd(), col, &lvCol) != 0; |
2bda0e17 KB |
662 | } |
663 | ||
664 | // Gets the column width | |
debe6624 | 665 | int wxListCtrl::GetColumnWidth(int col) const |
2bda0e17 | 666 | { |
edccf428 | 667 | return ListView_GetColumnWidth(GetHwnd(), col); |
2bda0e17 KB |
668 | } |
669 | ||
670 | // Sets the column width | |
debe6624 | 671 | bool wxListCtrl::SetColumnWidth(int col, int width) |
2bda0e17 | 672 | { |
0b5efdc7 VZ |
673 | int col2 = col; |
674 | if ( m_windowStyle & wxLC_LIST ) | |
675 | col2 = -1; | |
2bda0e17 | 676 | |
0b5efdc7 VZ |
677 | int width2 = width; |
678 | if ( width2 == wxLIST_AUTOSIZE) | |
679 | width2 = LVSCW_AUTOSIZE; | |
680 | else if ( width2 == wxLIST_AUTOSIZE_USEHEADER) | |
681 | width2 = LVSCW_AUTOSIZE_USEHEADER; | |
2bda0e17 | 682 | |
6f806543 | 683 | return ListView_SetColumnWidth(GetHwnd(), col2, width2) != 0; |
2bda0e17 KB |
684 | } |
685 | ||
686 | // Gets the number of items that can fit vertically in the | |
687 | // visible area of the list control (list or report view) | |
688 | // or the total number of items in the list control (icon | |
689 | // or small icon view) | |
c42404a5 | 690 | int wxListCtrl::GetCountPerPage() const |
2bda0e17 | 691 | { |
edccf428 | 692 | return ListView_GetCountPerPage(GetHwnd()); |
2bda0e17 KB |
693 | } |
694 | ||
695 | // Gets the edit control for editing labels. | |
c42404a5 | 696 | wxTextCtrl* wxListCtrl::GetEditControl() const |
2bda0e17 | 697 | { |
bbcdf8bc | 698 | return m_textCtrl; |
2bda0e17 KB |
699 | } |
700 | ||
701 | // Gets information about the item | |
702 | bool wxListCtrl::GetItem(wxListItem& info) const | |
703 | { | |
0b5efdc7 | 704 | LV_ITEM lvItem; |
11c7d5b6 | 705 | wxZeroMemory(lvItem); |
2bda0e17 | 706 | |
0b5efdc7 | 707 | lvItem.iItem = info.m_itemId; |
fc5a93cd | 708 | lvItem.iSubItem = info.m_col; |
0b5efdc7 VZ |
709 | |
710 | if ( info.m_mask & wxLIST_MASK_TEXT ) | |
711 | { | |
712 | lvItem.mask |= LVIF_TEXT; | |
837e5743 | 713 | lvItem.pszText = new wxChar[513]; |
0b5efdc7 VZ |
714 | lvItem.cchTextMax = 512; |
715 | } | |
716 | else | |
717 | { | |
718 | lvItem.pszText = NULL; | |
719 | } | |
720 | ||
721 | if (info.m_mask & wxLIST_MASK_DATA) | |
edccf428 | 722 | lvItem.mask |= LVIF_PARAM; |
0b5efdc7 | 723 | |
2189c644 JS |
724 | if (info.m_mask & wxLIST_MASK_IMAGE) |
725 | lvItem.mask |= LVIF_IMAGE; | |
726 | ||
0b5efdc7 VZ |
727 | if ( info.m_mask & wxLIST_MASK_STATE ) |
728 | { | |
729 | lvItem.mask |= LVIF_STATE; | |
730 | // the other bits are hardly interesting anyhow | |
731 | lvItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED; | |
732 | } | |
733 | ||
734 | bool success = ListView_GetItem((HWND)GetHWND(), &lvItem) != 0; | |
735 | if ( !success ) | |
736 | { | |
737 | wxLogError(_("Couldn't retrieve information about list control item %d."), | |
738 | lvItem.iItem); | |
739 | } | |
740 | else | |
741 | { | |
dccde0c0 VZ |
742 | // give NULL as hwnd as we already have everything we need |
743 | wxConvertFromMSWListItem(NULL, info, lvItem); | |
0b5efdc7 VZ |
744 | } |
745 | ||
746 | if (lvItem.pszText) | |
747 | delete[] lvItem.pszText; | |
748 | ||
749 | return success; | |
2bda0e17 KB |
750 | } |
751 | ||
752 | // Sets information about the item | |
753 | bool wxListCtrl::SetItem(wxListItem& info) | |
754 | { | |
0b5efdc7 | 755 | LV_ITEM item; |
2bda0e17 | 756 | wxConvertToMSWListItem(this, info, item); |
bdc72a22 | 757 | |
7cf46fdb VZ |
758 | // we never update the lParam if it contains our pointer |
759 | // to the wxListItemInternalData structure | |
760 | item.mask &= ~LVIF_PARAM; | |
761 | ||
762 | // check if setting attributes or lParam | |
763 | if (info.HasAttributes() || (info.m_mask & wxLIST_MASK_DATA)) | |
764 | { | |
765 | // get internal item data | |
766 | // perhaps a cache here ? | |
6149de71 | 767 | wxListItemInternalData *data = wxGetInternalData(this, info.m_itemId); |
73d8c5fd | 768 | |
7cf46fdb VZ |
769 | if (! data) |
770 | { | |
771 | // need to set it | |
772 | m_AnyInternalData = TRUE; | |
773 | data = new wxListItemInternalData(); | |
774 | item.lParam = (LPARAM) data; | |
775 | item.mask |= LVIF_PARAM; | |
776 | }; | |
777 | ||
778 | ||
779 | // user data | |
780 | if (info.m_mask & wxLIST_MASK_DATA) | |
781 | data->lParam = info.m_data; | |
782 | ||
783 | // attributes | |
784 | if (info.HasAttributes()) | |
785 | { | |
786 | if (data->attr) | |
787 | *data->attr = *info.GetAttributes(); | |
788 | else | |
789 | data->attr = new wxListItemAttr(*info.GetAttributes()); | |
790 | }; | |
791 | }; | |
792 | ||
793 | ||
2d33aec9 VZ |
794 | // we could be changing only the attribute in which case we don't need to |
795 | // call ListView_SetItem() at all | |
796 | if ( item.mask ) | |
bdc72a22 | 797 | { |
2d33aec9 VZ |
798 | item.cchTextMax = 0; |
799 | if ( !ListView_SetItem(GetHwnd(), &item) ) | |
800 | { | |
801 | wxLogDebug(_T("ListView_SetItem() failed")); | |
2702ed5a | 802 | |
2d33aec9 VZ |
803 | return FALSE; |
804 | } | |
233d0295 | 805 | } |
2702ed5a | 806 | |
233d0295 VZ |
807 | // we need to update the item immediately to show the new image |
808 | bool updateNow = (info.m_mask & wxLIST_MASK_IMAGE) != 0; | |
2702ed5a | 809 | |
233d0295 VZ |
810 | // check whether it has any custom attributes |
811 | if ( info.HasAttributes() ) | |
812 | { | |
bdc72a22 | 813 | m_hasAnyAttr = TRUE; |
233d0295 VZ |
814 | |
815 | // if the colour has changed, we must redraw the item | |
816 | updateNow = TRUE; | |
bdc72a22 | 817 | } |
bdc72a22 | 818 | |
233d0295 | 819 | if ( updateNow ) |
7cc98b3e | 820 | { |
233d0295 | 821 | // we need this to make the change visible right now |
2d33aec9 | 822 | RefreshItem(item.iItem); |
7cc98b3e VZ |
823 | } |
824 | ||
233d0295 | 825 | return TRUE; |
2bda0e17 KB |
826 | } |
827 | ||
debe6624 | 828 | long wxListCtrl::SetItem(long index, int col, const wxString& label, int imageId) |
2bda0e17 | 829 | { |
0b5efdc7 VZ |
830 | wxListItem info; |
831 | info.m_text = label; | |
832 | info.m_mask = wxLIST_MASK_TEXT; | |
833 | info.m_itemId = index; | |
834 | info.m_col = col; | |
835 | if ( imageId > -1 ) | |
836 | { | |
837 | info.m_image = imageId; | |
838 | info.m_mask |= wxLIST_MASK_IMAGE; | |
839 | } | |
840 | return SetItem(info); | |
2bda0e17 KB |
841 | } |
842 | ||
843 | ||
844 | // Gets the item state | |
debe6624 | 845 | int wxListCtrl::GetItemState(long item, long stateMask) const |
2bda0e17 | 846 | { |
0b5efdc7 | 847 | wxListItem info; |
2bda0e17 | 848 | |
edccf428 | 849 | info.m_mask = wxLIST_MASK_STATE; |
0b5efdc7 VZ |
850 | info.m_stateMask = stateMask; |
851 | info.m_itemId = item; | |
2bda0e17 | 852 | |
0b5efdc7 VZ |
853 | if (!GetItem(info)) |
854 | return 0; | |
2bda0e17 | 855 | |
0b5efdc7 | 856 | return info.m_state; |
2bda0e17 KB |
857 | } |
858 | ||
859 | // Sets the item state | |
debe6624 | 860 | bool wxListCtrl::SetItemState(long item, long state, long stateMask) |
2bda0e17 | 861 | { |
8dff2b5c VZ |
862 | // NB: don't use SetItem() here as it doesn't work with the virtual list |
863 | // controls | |
864 | LV_ITEM lvItem; | |
865 | wxZeroMemory(lvItem); | |
2bda0e17 | 866 | |
8dff2b5c | 867 | wxConvertToMSWFlags(state, stateMask, lvItem); |
2bda0e17 | 868 | |
2d33aec9 | 869 | // for the virtual list controls we need to refresh the previously focused |
ad9f477d VZ |
870 | // item manually when changing focus without changing selection |
871 | // programmatically because otherwise it keeps its focus rectangle until | |
872 | // next repaint (yet another comctl32 bug) | |
2d33aec9 VZ |
873 | long focusOld; |
874 | if ( IsVirtual() && | |
875 | (stateMask & wxLIST_STATE_FOCUSED) && | |
876 | (state & wxLIST_STATE_FOCUSED) ) | |
877 | { | |
878 | focusOld = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED); | |
879 | } | |
880 | else | |
881 | { | |
882 | focusOld = -1; | |
883 | } | |
884 | ||
8dff2b5c VZ |
885 | if ( !::SendMessage(GetHwnd(), LVM_SETITEMSTATE, |
886 | (WPARAM)item, (LPARAM)&lvItem) ) | |
887 | { | |
888 | wxLogLastError(_T("ListView_SetItemState")); | |
889 | ||
890 | return FALSE; | |
891 | } | |
892 | ||
2d33aec9 VZ |
893 | if ( focusOld != -1 ) |
894 | { | |
ad9f477d VZ |
895 | // no need to refresh the item if it was previously selected, it would |
896 | // only result in annoying flicker | |
897 | if ( !(GetItemState(focusOld, | |
898 | wxLIST_STATE_SELECTED) & wxLIST_STATE_SELECTED) ) | |
899 | { | |
900 | RefreshItem(focusOld); | |
901 | } | |
2d33aec9 VZ |
902 | } |
903 | ||
8dff2b5c | 904 | return TRUE; |
2bda0e17 KB |
905 | } |
906 | ||
907 | // Sets the item image | |
33ac7e6f | 908 | bool wxListCtrl::SetItemImage(long item, int image, int WXUNUSED(selImage)) |
2bda0e17 | 909 | { |
0b5efdc7 | 910 | wxListItem info; |
2bda0e17 | 911 | |
edccf428 | 912 | info.m_mask = wxLIST_MASK_IMAGE; |
0b5efdc7 VZ |
913 | info.m_image = image; |
914 | info.m_itemId = item; | |
2bda0e17 | 915 | |
0b5efdc7 | 916 | return SetItem(info); |
2bda0e17 KB |
917 | } |
918 | ||
919 | // Gets the item text | |
debe6624 | 920 | wxString wxListCtrl::GetItemText(long item) const |
2bda0e17 | 921 | { |
0b5efdc7 | 922 | wxListItem info; |
2bda0e17 | 923 | |
edccf428 | 924 | info.m_mask = wxLIST_MASK_TEXT; |
0b5efdc7 | 925 | info.m_itemId = item; |
2bda0e17 | 926 | |
0b5efdc7 | 927 | if (!GetItem(info)) |
2b5f62a0 | 928 | return wxEmptyString; |
0b5efdc7 | 929 | return info.m_text; |
2bda0e17 KB |
930 | } |
931 | ||
932 | // Sets the item text | |
debe6624 | 933 | void wxListCtrl::SetItemText(long item, const wxString& str) |
2bda0e17 | 934 | { |
0b5efdc7 | 935 | wxListItem info; |
2bda0e17 | 936 | |
edccf428 | 937 | info.m_mask = wxLIST_MASK_TEXT; |
0b5efdc7 VZ |
938 | info.m_itemId = item; |
939 | info.m_text = str; | |
2bda0e17 | 940 | |
0b5efdc7 | 941 | SetItem(info); |
2bda0e17 KB |
942 | } |
943 | ||
944 | // Gets the item data | |
debe6624 | 945 | long wxListCtrl::GetItemData(long item) const |
2bda0e17 | 946 | { |
0b5efdc7 | 947 | wxListItem info; |
2bda0e17 | 948 | |
edccf428 | 949 | info.m_mask = wxLIST_MASK_DATA; |
0b5efdc7 | 950 | info.m_itemId = item; |
2bda0e17 | 951 | |
0b5efdc7 VZ |
952 | if (!GetItem(info)) |
953 | return 0; | |
954 | return info.m_data; | |
2bda0e17 KB |
955 | } |
956 | ||
957 | // Sets the item data | |
debe6624 | 958 | bool wxListCtrl::SetItemData(long item, long data) |
2bda0e17 | 959 | { |
0b5efdc7 | 960 | wxListItem info; |
2bda0e17 | 961 | |
edccf428 | 962 | info.m_mask = wxLIST_MASK_DATA; |
0b5efdc7 VZ |
963 | info.m_itemId = item; |
964 | info.m_data = data; | |
2bda0e17 | 965 | |
0b5efdc7 | 966 | return SetItem(info); |
2bda0e17 KB |
967 | } |
968 | ||
969 | // Gets the item rectangle | |
16e93305 | 970 | bool wxListCtrl::GetItemRect(long item, wxRect& rect, int code) const |
2bda0e17 | 971 | { |
2d33aec9 | 972 | RECT rectWin; |
2bda0e17 | 973 | |
2d33aec9 | 974 | int codeWin; |
0b5efdc7 | 975 | if ( code == wxLIST_RECT_BOUNDS ) |
2d33aec9 | 976 | codeWin = LVIR_BOUNDS; |
0b5efdc7 | 977 | else if ( code == wxLIST_RECT_ICON ) |
2d33aec9 | 978 | codeWin = LVIR_ICON; |
0b5efdc7 | 979 | else if ( code == wxLIST_RECT_LABEL ) |
2d33aec9 VZ |
980 | codeWin = LVIR_LABEL; |
981 | else | |
982 | { | |
983 | wxFAIL_MSG( _T("incorrect code in GetItemRect()") ); | |
984 | ||
985 | codeWin = LVIR_BOUNDS; | |
986 | } | |
2bda0e17 | 987 | |
2d33aec9 | 988 | bool success = ListView_GetItemRect(GetHwnd(), (int) item, &rectWin, codeWin) != 0; |
2bda0e17 | 989 | |
2d33aec9 VZ |
990 | rect.x = rectWin.left; |
991 | rect.y = rectWin.top; | |
992 | rect.width = rectWin.right - rectWin.left; | |
993 | rect.height = rectWin.bottom - rectWin.top; | |
994 | ||
0b5efdc7 | 995 | return success; |
2bda0e17 KB |
996 | } |
997 | ||
998 | // Gets the item position | |
debe6624 | 999 | bool wxListCtrl::GetItemPosition(long item, wxPoint& pos) const |
2bda0e17 | 1000 | { |
0b5efdc7 | 1001 | POINT pt; |
2bda0e17 | 1002 | |
edccf428 | 1003 | bool success = (ListView_GetItemPosition(GetHwnd(), (int) item, &pt) != 0); |
2bda0e17 | 1004 | |
0b5efdc7 VZ |
1005 | pos.x = pt.x; pos.y = pt.y; |
1006 | return success; | |
2bda0e17 KB |
1007 | } |
1008 | ||
1009 | // Sets the item position. | |
debe6624 | 1010 | bool wxListCtrl::SetItemPosition(long item, const wxPoint& pos) |
2bda0e17 | 1011 | { |
edccf428 | 1012 | return (ListView_SetItemPosition(GetHwnd(), (int) item, pos.x, pos.y) != 0); |
2bda0e17 KB |
1013 | } |
1014 | ||
1015 | // Gets the number of items in the list control | |
c42404a5 | 1016 | int wxListCtrl::GetItemCount() const |
2bda0e17 | 1017 | { |
edccf428 | 1018 | return ListView_GetItemCount(GetHwnd()); |
2bda0e17 KB |
1019 | } |
1020 | ||
1021 | // Retrieves the spacing between icons in pixels. | |
1022 | // If small is TRUE, gets the spacing for the small icon | |
1023 | // view, otherwise the large icon view. | |
1024 | int wxListCtrl::GetItemSpacing(bool isSmall) const | |
1025 | { | |
edccf428 | 1026 | return ListView_GetItemSpacing(GetHwnd(), (BOOL) isSmall); |
2bda0e17 KB |
1027 | } |
1028 | ||
5b98eb2f RL |
1029 | void wxListCtrl::SetItemTextColour( long item, const wxColour &col ) |
1030 | { | |
1031 | wxListItem info; | |
1032 | info.m_itemId = item; | |
1033 | info.SetTextColour( col ); | |
1034 | SetItem( info ); | |
1035 | } | |
1036 | ||
1037 | wxColour wxListCtrl::GetItemTextColour( long item ) const | |
1038 | { | |
1039 | wxListItem info; | |
1040 | info.m_itemId = item; | |
1041 | GetItem( info ); | |
1042 | return info.GetTextColour(); | |
1043 | } | |
1044 | ||
1045 | void wxListCtrl::SetItemBackgroundColour( long item, const wxColour &col ) | |
1046 | { | |
1047 | wxListItem info; | |
1048 | info.m_itemId = item; | |
1049 | info.SetBackgroundColour( col ); | |
1050 | SetItem( info ); | |
1051 | } | |
1052 | ||
1053 | wxColour wxListCtrl::GetItemBackgroundColour( long item ) const | |
1054 | { | |
1055 | wxListItem info; | |
1056 | info.m_itemId = item; | |
1057 | GetItem( info ); | |
1058 | return info.GetBackgroundColour(); | |
1059 | } | |
1060 | ||
2bda0e17 | 1061 | // Gets the number of selected items in the list control |
c42404a5 | 1062 | int wxListCtrl::GetSelectedItemCount() const |
2bda0e17 | 1063 | { |
edccf428 | 1064 | return ListView_GetSelectedCount(GetHwnd()); |
2bda0e17 KB |
1065 | } |
1066 | ||
1067 | // Gets the text colour of the listview | |
c42404a5 | 1068 | wxColour wxListCtrl::GetTextColour() const |
2bda0e17 | 1069 | { |
edccf428 | 1070 | COLORREF ref = ListView_GetTextColor(GetHwnd()); |
0b5efdc7 VZ |
1071 | wxColour col(GetRValue(ref), GetGValue(ref), GetBValue(ref)); |
1072 | return col; | |
2bda0e17 KB |
1073 | } |
1074 | ||
1075 | // Sets the text colour of the listview | |
1076 | void wxListCtrl::SetTextColour(const wxColour& col) | |
1077 | { | |
910484a6 | 1078 | ListView_SetTextColor(GetHwnd(), PALETTERGB(col.Red(), col.Green(), col.Blue())); |
2bda0e17 KB |
1079 | } |
1080 | ||
1081 | // Gets the index of the topmost visible item when in | |
1082 | // list or report view | |
c42404a5 | 1083 | long wxListCtrl::GetTopItem() const |
2bda0e17 | 1084 | { |
edccf428 | 1085 | return (long) ListView_GetTopIndex(GetHwnd()); |
2bda0e17 KB |
1086 | } |
1087 | ||
1088 | // Searches for an item, starting from 'item'. | |
1089 | // 'geometry' is one of | |
1090 | // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT. | |
1091 | // 'state' is a state bit flag, one or more of | |
1092 | // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT. | |
1093 | // item can be -1 to find the first item that matches the | |
1094 | // specified flags. | |
1095 | // Returns the item or -1 if unsuccessful. | |
debe6624 | 1096 | long wxListCtrl::GetNextItem(long item, int geom, int state) const |
2bda0e17 | 1097 | { |
0b5efdc7 | 1098 | long flags = 0; |
2bda0e17 | 1099 | |
0b5efdc7 VZ |
1100 | if ( geom == wxLIST_NEXT_ABOVE ) |
1101 | flags |= LVNI_ABOVE; | |
1102 | if ( geom == wxLIST_NEXT_ALL ) | |
1103 | flags |= LVNI_ALL; | |
1104 | if ( geom == wxLIST_NEXT_BELOW ) | |
1105 | flags |= LVNI_BELOW; | |
1106 | if ( geom == wxLIST_NEXT_LEFT ) | |
1107 | flags |= LVNI_TOLEFT; | |
1108 | if ( geom == wxLIST_NEXT_RIGHT ) | |
1109 | flags |= LVNI_TORIGHT; | |
2bda0e17 | 1110 | |
0b5efdc7 VZ |
1111 | if ( state & wxLIST_STATE_CUT ) |
1112 | flags |= LVNI_CUT; | |
1113 | if ( state & wxLIST_STATE_DROPHILITED ) | |
1114 | flags |= LVNI_DROPHILITED; | |
1115 | if ( state & wxLIST_STATE_FOCUSED ) | |
1116 | flags |= LVNI_FOCUSED; | |
1117 | if ( state & wxLIST_STATE_SELECTED ) | |
1118 | flags |= LVNI_SELECTED; | |
2bda0e17 | 1119 | |
edccf428 | 1120 | return (long) ListView_GetNextItem(GetHwnd(), item, flags); |
2bda0e17 KB |
1121 | } |
1122 | ||
1123 | ||
debe6624 | 1124 | wxImageList *wxListCtrl::GetImageList(int which) const |
2bda0e17 | 1125 | { |
0b5efdc7 | 1126 | if ( which == wxIMAGE_LIST_NORMAL ) |
2bda0e17 | 1127 | { |
0b5efdc7 VZ |
1128 | return m_imageListNormal; |
1129 | } | |
1130 | else if ( which == wxIMAGE_LIST_SMALL ) | |
2bda0e17 | 1131 | { |
0b5efdc7 VZ |
1132 | return m_imageListSmall; |
1133 | } | |
1134 | else if ( which == wxIMAGE_LIST_STATE ) | |
2bda0e17 | 1135 | { |
0b5efdc7 VZ |
1136 | return m_imageListState; |
1137 | } | |
1138 | return NULL; | |
2bda0e17 KB |
1139 | } |
1140 | ||
debe6624 | 1141 | void wxListCtrl::SetImageList(wxImageList *imageList, int which) |
2bda0e17 | 1142 | { |
0b5efdc7 VZ |
1143 | int flags = 0; |
1144 | if ( which == wxIMAGE_LIST_NORMAL ) | |
2bda0e17 | 1145 | { |
0b5efdc7 | 1146 | flags = LVSIL_NORMAL; |
2e12c11a | 1147 | if (m_ownsImageListNormal) delete m_imageListNormal; |
0b5efdc7 | 1148 | m_imageListNormal = imageList; |
2e12c11a | 1149 | m_ownsImageListNormal = FALSE; |
0b5efdc7 VZ |
1150 | } |
1151 | else if ( which == wxIMAGE_LIST_SMALL ) | |
2bda0e17 | 1152 | { |
0b5efdc7 | 1153 | flags = LVSIL_SMALL; |
2e12c11a | 1154 | if (m_ownsImageListSmall) delete m_imageListSmall; |
0b5efdc7 | 1155 | m_imageListSmall = imageList; |
2e12c11a | 1156 | m_ownsImageListSmall = FALSE; |
0b5efdc7 VZ |
1157 | } |
1158 | else if ( which == wxIMAGE_LIST_STATE ) | |
2bda0e17 | 1159 | { |
0b5efdc7 | 1160 | flags = LVSIL_STATE; |
2e12c11a | 1161 | if (m_ownsImageListState) delete m_imageListState; |
0b5efdc7 | 1162 | m_imageListState = imageList; |
2e12c11a | 1163 | m_ownsImageListState = FALSE; |
0b5efdc7 | 1164 | } |
edccf428 | 1165 | ListView_SetImageList(GetHwnd(), (HIMAGELIST) imageList ? imageList->GetHIMAGELIST() : 0, flags); |
2bda0e17 KB |
1166 | } |
1167 | ||
2e12c11a VS |
1168 | void wxListCtrl::AssignImageList(wxImageList *imageList, int which) |
1169 | { | |
1170 | SetImageList(imageList, which); | |
1171 | if ( which == wxIMAGE_LIST_NORMAL ) | |
1172 | m_ownsImageListNormal = TRUE; | |
1173 | else if ( which == wxIMAGE_LIST_SMALL ) | |
1174 | m_ownsImageListSmall = TRUE; | |
1175 | else if ( which == wxIMAGE_LIST_STATE ) | |
1176 | m_ownsImageListState = TRUE; | |
1177 | } | |
1178 | ||
edccf428 | 1179 | // ---------------------------------------------------------------------------- |
2bda0e17 | 1180 | // Operations |
edccf428 | 1181 | // ---------------------------------------------------------------------------- |
2bda0e17 KB |
1182 | |
1183 | // Arranges the items | |
debe6624 | 1184 | bool wxListCtrl::Arrange(int flag) |
2bda0e17 | 1185 | { |
0b5efdc7 VZ |
1186 | UINT code = 0; |
1187 | if ( flag == wxLIST_ALIGN_LEFT ) | |
1188 | code = LVA_ALIGNLEFT; | |
1189 | else if ( flag == wxLIST_ALIGN_TOP ) | |
1190 | code = LVA_ALIGNTOP; | |
1191 | else if ( flag == wxLIST_ALIGN_DEFAULT ) | |
1192 | code = LVA_DEFAULT; | |
1193 | else if ( flag == wxLIST_ALIGN_SNAP_TO_GRID ) | |
1194 | code = LVA_SNAPTOGRID; | |
2bda0e17 | 1195 | |
edccf428 | 1196 | return (ListView_Arrange(GetHwnd(), code) != 0); |
2bda0e17 KB |
1197 | } |
1198 | ||
1199 | // Deletes an item | |
debe6624 | 1200 | bool wxListCtrl::DeleteItem(long item) |
2bda0e17 | 1201 | { |
2e9f62da VZ |
1202 | if ( !ListView_DeleteItem(GetHwnd(), (int) item) ) |
1203 | { | |
1204 | wxLogLastError(_T("ListView_DeleteItem")); | |
1205 | return FALSE; | |
1206 | } | |
1207 | ||
1208 | // the virtual list control doesn't refresh itself correctly, help it | |
1209 | if ( IsVirtual() ) | |
1210 | { | |
1211 | // we need to refresh all the lines below the one which was deleted | |
1212 | wxRect rectItem; | |
1213 | if ( item > 0 && GetItemCount() ) | |
1214 | { | |
1215 | GetItemRect(item - 1, rectItem); | |
1216 | } | |
1217 | else | |
1218 | { | |
1219 | rectItem.y = | |
1220 | rectItem.height = 0; | |
1221 | } | |
1222 | ||
1223 | wxRect rectWin = GetRect(); | |
1224 | rectWin.height = rectWin.GetBottom() - rectItem.GetBottom(); | |
1225 | rectWin.y = rectItem.GetBottom(); | |
1226 | ||
1227 | RefreshRect(rectWin); | |
1228 | } | |
1229 | ||
1230 | return TRUE; | |
2bda0e17 KB |
1231 | } |
1232 | ||
1233 | // Deletes all items | |
0b5efdc7 | 1234 | bool wxListCtrl::DeleteAllItems() |
2bda0e17 | 1235 | { |
2e9f62da | 1236 | return ListView_DeleteAllItems(GetHwnd()) != 0; |
2bda0e17 KB |
1237 | } |
1238 | ||
1239 | // Deletes all items | |
0b5efdc7 | 1240 | bool wxListCtrl::DeleteAllColumns() |
2bda0e17 | 1241 | { |
edccf428 | 1242 | while ( m_colCount > 0 ) |
2bda0e17 | 1243 | { |
edccf428 VZ |
1244 | if ( ListView_DeleteColumn(GetHwnd(), 0) == 0 ) |
1245 | { | |
f6bcfd97 | 1246 | wxLogLastError(wxT("ListView_DeleteColumn")); |
edccf428 VZ |
1247 | |
1248 | return FALSE; | |
1249 | } | |
1250 | ||
1251 | m_colCount--; | |
2bda0e17 | 1252 | } |
edccf428 | 1253 | |
223d09f6 | 1254 | wxASSERT_MSG( m_colCount == 0, wxT("no columns should be left") ); |
edccf428 VZ |
1255 | |
1256 | return TRUE; | |
2bda0e17 KB |
1257 | } |
1258 | ||
1259 | // Deletes a column | |
debe6624 | 1260 | bool wxListCtrl::DeleteColumn(int col) |
2bda0e17 | 1261 | { |
edccf428 | 1262 | bool success = (ListView_DeleteColumn(GetHwnd(), col) != 0); |
2bda0e17 KB |
1263 | |
1264 | if ( success && (m_colCount > 0) ) | |
1265 | m_colCount --; | |
1266 | return success; | |
1267 | } | |
1268 | ||
1269 | // Clears items, and columns if there are any. | |
0b5efdc7 | 1270 | void wxListCtrl::ClearAll() |
2bda0e17 KB |
1271 | { |
1272 | DeleteAllItems(); | |
1273 | if ( m_colCount > 0 ) | |
1274 | DeleteAllColumns(); | |
1275 | } | |
1276 | ||
bbcdf8bc JS |
1277 | wxTextCtrl* wxListCtrl::EditLabel(long item, wxClassInfo* textControlClass) |
1278 | { | |
1279 | wxASSERT( (textControlClass->IsKindOf(CLASSINFO(wxTextCtrl))) ); | |
1280 | ||
6aaef140 | 1281 | // ListView_EditLabel requires that the list has focus. |
aa50e893 | 1282 | SetFocus(); |
2b5f62a0 | 1283 | |
6aaef140 | 1284 | WXHWND hWnd = (WXHWND) ListView_EditLabel(GetHwnd(), item); |
2b5f62a0 VZ |
1285 | if ( !hWnd ) |
1286 | { | |
1287 | // failed to start editing | |
1288 | return NULL; | |
1289 | } | |
bbcdf8bc | 1290 | |
2b5f62a0 VZ |
1291 | // [re]create the text control wrapping the HWND we got |
1292 | if ( m_textCtrl ) | |
bbcdf8bc | 1293 | { |
0b5efdc7 | 1294 | m_textCtrl->SetHWND(0); |
7bf1474a | 1295 | m_textCtrl->UnsubclassWin(); |
0b5efdc7 | 1296 | delete m_textCtrl; |
bbcdf8bc JS |
1297 | } |
1298 | ||
2b5f62a0 | 1299 | m_textCtrl = (wxTextCtrl *)textControlClass->CreateObject(); |
6aaef140 VZ |
1300 | m_textCtrl->SetHWND(hWnd); |
1301 | m_textCtrl->SubclassWin(hWnd); | |
1302 | m_textCtrl->SetParent(this); | |
bbcdf8bc | 1303 | |
2b5f62a0 VZ |
1304 | // we must disallow TABbing away from the control while the edit contol is |
1305 | // shown because this leaves it in some strange state (just try removing | |
1306 | // this line and then pressing TAB while editing an item in listctrl | |
1307 | // inside a panel) | |
1308 | m_textCtrl->SetWindowStyle(m_textCtrl->GetWindowStyle() | wxTE_PROCESS_TAB); | |
1309 | ||
bbcdf8bc JS |
1310 | return m_textCtrl; |
1311 | } | |
1312 | ||
1313 | // End label editing, optionally cancelling the edit | |
33ac7e6f | 1314 | bool wxListCtrl::EndEditLabel(bool WXUNUSED(cancel)) |
2bda0e17 | 1315 | { |
7bf1474a VZ |
1316 | wxFAIL_MSG( _T("not implemented") ); |
1317 | ||
0b5efdc7 | 1318 | return FALSE; |
2bda0e17 KB |
1319 | } |
1320 | ||
1321 | // Ensures this item is visible | |
debe6624 | 1322 | bool wxListCtrl::EnsureVisible(long item) |
2bda0e17 | 1323 | { |
7bf1474a | 1324 | return ListView_EnsureVisible(GetHwnd(), (int) item, FALSE) != 0; |
2bda0e17 KB |
1325 | } |
1326 | ||
1327 | // Find an item whose label matches this string, starting from the item after 'start' | |
1328 | // or the beginning if 'start' is -1. | |
debe6624 | 1329 | long wxListCtrl::FindItem(long start, const wxString& str, bool partial) |
2bda0e17 | 1330 | { |
0b5efdc7 | 1331 | LV_FINDINFO findInfo; |
2bda0e17 | 1332 | |
0b5efdc7 VZ |
1333 | findInfo.flags = LVFI_STRING; |
1334 | if ( partial ) | |
7edc258e | 1335 | findInfo.flags |= LVFI_PARTIAL; |
3ca6a5f0 | 1336 | findInfo.psz = str; |
2bda0e17 | 1337 | |
3ca6a5f0 BP |
1338 | // ListView_FindItem() excludes the first item from search and to look |
1339 | // through all the items you need to start from -1 which is unnatural and | |
8036af01 JS |
1340 | // inconsistent with the generic version - so we adjust the index |
1341 | if (start != -1) | |
1342 | start --; | |
1343 | return ListView_FindItem(GetHwnd(), (int) start, &findInfo); | |
2bda0e17 KB |
1344 | } |
1345 | ||
1346 | // Find an item whose data matches this data, starting from the item after 'start' | |
1347 | // or the beginning if 'start' is -1. | |
72db8894 RD |
1348 | // NOTE : Lindsay Mathieson - 14-July-2002 |
1349 | // No longer use ListView_FindItem as the data attribute is now stored | |
1350 | // in a wxListItemInternalData structure refernced by the actual lParam | |
debe6624 | 1351 | long wxListCtrl::FindItem(long start, long data) |
2bda0e17 | 1352 | { |
72db8894 RD |
1353 | long idx = start + 1; |
1354 | long count = GetItemCount(); | |
2bda0e17 | 1355 | |
72db8894 RD |
1356 | while (idx < count) |
1357 | { | |
1358 | if (GetItemData(idx) == data) | |
1359 | return idx; | |
1360 | idx++; | |
1361 | }; | |
2bda0e17 | 1362 | |
72db8894 | 1363 | return -1; |
2bda0e17 KB |
1364 | } |
1365 | ||
1366 | // Find an item nearest this position in the specified direction, starting from | |
1367 | // the item after 'start' or the beginning if 'start' is -1. | |
debe6624 | 1368 | long wxListCtrl::FindItem(long start, const wxPoint& pt, int direction) |
2bda0e17 | 1369 | { |
0b5efdc7 | 1370 | LV_FINDINFO findInfo; |
2bda0e17 | 1371 | |
0b5efdc7 VZ |
1372 | findInfo.flags = LVFI_NEARESTXY; |
1373 | findInfo.pt.x = pt.x; | |
1374 | findInfo.pt.y = pt.y; | |
acb62b84 | 1375 | findInfo.vkDirection = VK_RIGHT; |
2bda0e17 | 1376 | |
0b5efdc7 VZ |
1377 | if ( direction == wxLIST_FIND_UP ) |
1378 | findInfo.vkDirection = VK_UP; | |
1379 | else if ( direction == wxLIST_FIND_DOWN ) | |
1380 | findInfo.vkDirection = VK_DOWN; | |
1381 | else if ( direction == wxLIST_FIND_LEFT ) | |
1382 | findInfo.vkDirection = VK_LEFT; | |
1383 | else if ( direction == wxLIST_FIND_RIGHT ) | |
1384 | findInfo.vkDirection = VK_RIGHT; | |
1385 | ||
edccf428 | 1386 | return ListView_FindItem(GetHwnd(), (int) start, & findInfo); |
2bda0e17 KB |
1387 | } |
1388 | ||
1389 | // Determines which item (if any) is at the specified point, | |
1390 | // giving details in 'flags' (see wxLIST_HITTEST_... flags above) | |
1391 | long wxListCtrl::HitTest(const wxPoint& point, int& flags) | |
1392 | { | |
1393 | LV_HITTESTINFO hitTestInfo; | |
0b5efdc7 VZ |
1394 | hitTestInfo.pt.x = (int) point.x; |
1395 | hitTestInfo.pt.y = (int) point.y; | |
2bda0e17 | 1396 | |
edccf428 | 1397 | ListView_HitTest(GetHwnd(), & hitTestInfo); |
2bda0e17 | 1398 | |
0b5efdc7 VZ |
1399 | flags = 0; |
1400 | if ( hitTestInfo.flags & LVHT_ABOVE ) | |
1401 | flags |= wxLIST_HITTEST_ABOVE; | |
1402 | if ( hitTestInfo.flags & LVHT_BELOW ) | |
1403 | flags |= wxLIST_HITTEST_BELOW; | |
1404 | if ( hitTestInfo.flags & LVHT_NOWHERE ) | |
1405 | flags |= wxLIST_HITTEST_NOWHERE; | |
1406 | if ( hitTestInfo.flags & LVHT_ONITEMICON ) | |
1407 | flags |= wxLIST_HITTEST_ONITEMICON; | |
1408 | if ( hitTestInfo.flags & LVHT_ONITEMLABEL ) | |
1409 | flags |= wxLIST_HITTEST_ONITEMLABEL; | |
1410 | if ( hitTestInfo.flags & LVHT_ONITEMSTATEICON ) | |
1411 | flags |= wxLIST_HITTEST_ONITEMSTATEICON; | |
1412 | if ( hitTestInfo.flags & LVHT_TOLEFT ) | |
1413 | flags |= wxLIST_HITTEST_TOLEFT; | |
1414 | if ( hitTestInfo.flags & LVHT_TORIGHT ) | |
1415 | flags |= wxLIST_HITTEST_TORIGHT; | |
1416 | ||
edccf428 | 1417 | return (long) hitTestInfo.iItem; |
2bda0e17 KB |
1418 | } |
1419 | ||
1420 | // Inserts an item, returning the index of the new item if successful, | |
1421 | // -1 otherwise. | |
2bda0e17 KB |
1422 | long wxListCtrl::InsertItem(wxListItem& info) |
1423 | { | |
98ec9dbe VZ |
1424 | wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") ); |
1425 | ||
0b5efdc7 VZ |
1426 | LV_ITEM item; |
1427 | wxConvertToMSWListItem(this, info, item); | |
7cf46fdb | 1428 | item.mask &= ~LVIF_PARAM; |
2bda0e17 | 1429 | |
7cf46fdb VZ |
1430 | // check wether we need to allocate our internal data |
1431 | bool needInternalData = ((info.m_mask & wxLIST_MASK_DATA) || info.HasAttributes()); | |
1432 | if (needInternalData) | |
bdc72a22 | 1433 | { |
7cf46fdb VZ |
1434 | m_AnyInternalData = TRUE; |
1435 | item.mask |= LVIF_PARAM; | |
2702ed5a | 1436 | |
7cf46fdb VZ |
1437 | // internal stucture that manages data |
1438 | wxListItemInternalData *data = new wxListItemInternalData(); | |
1439 | item.lParam = (LPARAM) data; | |
2702ed5a | 1440 | |
7cf46fdb VZ |
1441 | if (info.m_mask & wxLIST_MASK_DATA) |
1442 | data->lParam = info.m_data; | |
2702ed5a | 1443 | |
7cf46fdb VZ |
1444 | // check whether it has any custom attributes |
1445 | if ( info.HasAttributes() ) | |
1446 | { | |
1447 | // take copy of attributes | |
1448 | data->attr = new wxListItemAttr(*info.GetAttributes()); | |
bdc72a22 | 1449 | } |
7cf46fdb VZ |
1450 | }; |
1451 | ||
bdc72a22 | 1452 | |
edccf428 | 1453 | return (long) ListView_InsertItem(GetHwnd(), & item); |
2bda0e17 KB |
1454 | } |
1455 | ||
debe6624 | 1456 | long wxListCtrl::InsertItem(long index, const wxString& label) |
2bda0e17 | 1457 | { |
0b5efdc7 VZ |
1458 | wxListItem info; |
1459 | info.m_text = label; | |
1460 | info.m_mask = wxLIST_MASK_TEXT; | |
1461 | info.m_itemId = index; | |
1462 | return InsertItem(info); | |
2bda0e17 KB |
1463 | } |
1464 | ||
1465 | // Inserts an image item | |
debe6624 | 1466 | long wxListCtrl::InsertItem(long index, int imageIndex) |
2bda0e17 | 1467 | { |
0b5efdc7 VZ |
1468 | wxListItem info; |
1469 | info.m_image = imageIndex; | |
1470 | info.m_mask = wxLIST_MASK_IMAGE; | |
1471 | info.m_itemId = index; | |
1472 | return InsertItem(info); | |
2bda0e17 KB |
1473 | } |
1474 | ||
1475 | // Inserts an image/string item | |
debe6624 | 1476 | long wxListCtrl::InsertItem(long index, const wxString& label, int imageIndex) |
2bda0e17 | 1477 | { |
0b5efdc7 VZ |
1478 | wxListItem info; |
1479 | info.m_image = imageIndex; | |
1480 | info.m_text = label; | |
1481 | info.m_mask = wxLIST_MASK_IMAGE | wxLIST_MASK_TEXT; | |
1482 | info.m_itemId = index; | |
1483 | return InsertItem(info); | |
2bda0e17 KB |
1484 | } |
1485 | ||
1486 | // For list view mode (only), inserts a column. | |
debe6624 | 1487 | long wxListCtrl::InsertColumn(long col, wxListItem& item) |
2bda0e17 | 1488 | { |
0b5efdc7 | 1489 | LV_COLUMN lvCol; |
6f806543 | 1490 | wxConvertToMSWListCol(col, item, lvCol); |
0b5efdc7 | 1491 | |
6f806543 | 1492 | if ( !(lvCol.mask & LVCF_WIDTH) ) |
e373f51b VZ |
1493 | { |
1494 | // always give some width to the new column: this one is compatible | |
6f806543 VZ |
1495 | // with the generic version |
1496 | lvCol.mask |= LVCF_WIDTH; | |
e373f51b | 1497 | lvCol.cx = 80; |
0b5efdc7 | 1498 | } |
e373f51b | 1499 | |
6f806543 VZ |
1500 | // when we insert a column which can contain an image, we must specify this |
1501 | // flag right now as doing it later in SetColumn() has no effect | |
1502 | // | |
1503 | // we use LVCFMT_BITMAP_ON_RIGHT by default because without it there is no | |
1504 | // way to dynamically set/clear the bitmap as the column without a bitmap | |
1505 | // on the left looks ugly (there is a hole) | |
1506 | // | |
1507 | // unfortunately with my version of comctl32.dll (5.80), the left column | |
1508 | // image is always on the left and it seems that it's a "feature" - I | |
1509 | // didn't find any way to work around it in any case | |
1510 | if ( lvCol.mask & LVCF_IMAGE ) | |
1511 | { | |
1512 | lvCol.mask |= LVCF_FMT; | |
1513 | lvCol.fmt |= LVCFMT_BITMAP_ON_RIGHT; | |
1514 | } | |
2bda0e17 | 1515 | |
6f806543 | 1516 | bool success = ListView_InsertColumn(GetHwnd(), col, &lvCol) != -1; |
2bda0e17 | 1517 | if ( success ) |
e373f51b VZ |
1518 | { |
1519 | m_colCount++; | |
1520 | } | |
1521 | else | |
1522 | { | |
223d09f6 | 1523 | wxLogDebug(wxT("Failed to insert the column '%s' into listview!"), |
e373f51b VZ |
1524 | lvCol.pszText); |
1525 | } | |
1526 | ||
2bda0e17 KB |
1527 | return success; |
1528 | } | |
1529 | ||
bdc72a22 VZ |
1530 | long wxListCtrl::InsertColumn(long col, |
1531 | const wxString& heading, | |
1532 | int format, | |
1533 | int width) | |
2bda0e17 | 1534 | { |
0b5efdc7 VZ |
1535 | wxListItem item; |
1536 | item.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_FORMAT; | |
1537 | item.m_text = heading; | |
1538 | if ( width > -1 ) | |
1539 | { | |
1540 | item.m_mask |= wxLIST_MASK_WIDTH; | |
1541 | item.m_width = width; | |
1542 | } | |
1543 | item.m_format = format; | |
2bda0e17 | 1544 | |
0b5efdc7 | 1545 | return InsertColumn(col, item); |
2bda0e17 KB |
1546 | } |
1547 | ||
2b5f62a0 VZ |
1548 | // scroll the control by the given number of pixels (exception: in list view, |
1549 | // dx is interpreted as number of columns) | |
debe6624 | 1550 | bool wxListCtrl::ScrollList(int dx, int dy) |
2bda0e17 | 1551 | { |
2b5f62a0 VZ |
1552 | if ( !ListView_Scroll(GetHwnd(), dx, dy) ) |
1553 | { | |
1554 | wxLogDebug(_T("ListView_Scroll(%d, %d) failed"), dx, dy); | |
1555 | ||
1556 | return FALSE; | |
1557 | } | |
1558 | ||
1559 | return TRUE; | |
2bda0e17 KB |
1560 | } |
1561 | ||
1562 | // Sort items. | |
1563 | ||
1564 | // fn is a function which takes 3 long arguments: item1, item2, data. | |
1565 | // item1 is the long data associated with a first item (NOT the index). | |
1566 | // item2 is the long data associated with a second item (NOT the index). | |
1567 | // data is the same value as passed to SortItems. | |
1568 | // The return value is a negative number if the first item should precede the second | |
1569 | // item, a positive number of the second item should precede the first, | |
1570 | // or zero if the two items are equivalent. | |
1571 | ||
1572 | // data is arbitrary data to be passed to the sort function. | |
19230604 | 1573 | |
7cf46fdb VZ |
1574 | // Internal structures for proxying the user compare function |
1575 | // so that we can pass it the *real* user data | |
19230604 | 1576 | |
7cf46fdb VZ |
1577 | // translate lParam data and call user func |
1578 | struct wxInternalDataSort | |
19230604 | 1579 | { |
7cf46fdb VZ |
1580 | wxListCtrlCompare user_fn; |
1581 | long data; | |
1582 | }; | |
19230604 | 1583 | |
7cf46fdb | 1584 | int CALLBACK wxInternalDataCompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort) |
2bda0e17 | 1585 | { |
7cf46fdb | 1586 | struct wxInternalDataSort *internalData = (struct wxInternalDataSort *) lParamSort; |
19230604 | 1587 | |
7cf46fdb VZ |
1588 | wxListItemInternalData *data1 = (wxListItemInternalData *) lParam1; |
1589 | wxListItemInternalData *data2 = (wxListItemInternalData *) lParam2; | |
19230604 | 1590 | |
7cf46fdb VZ |
1591 | long d1 = (data1 == NULL ? 0 : data1->lParam); |
1592 | long d2 = (data2 == NULL ? 0 : data2->lParam); | |
19230604 | 1593 | |
7cf46fdb | 1594 | return internalData->user_fn(d1, d2, internalData->data); |
19230604 | 1595 | |
7cf46fdb | 1596 | }; |
19230604 | 1597 | |
7cf46fdb VZ |
1598 | bool wxListCtrl::SortItems(wxListCtrlCompare fn, long data) |
1599 | { | |
1600 | struct wxInternalDataSort internalData; | |
1601 | internalData.user_fn = fn; | |
1602 | internalData.data = data; | |
19230604 | 1603 | |
14090241 VZ |
1604 | // WPARAM cast is needed for mingw/cygwin |
1605 | if ( !ListView_SortItems(GetHwnd(), | |
1606 | wxInternalDataCompareFunc, | |
1607 | (WPARAM) &internalData) ) | |
19230604 RD |
1608 | { |
1609 | wxLogDebug(_T("ListView_SortItems() failed")); | |
1610 | ||
1611 | return FALSE; | |
1612 | } | |
1613 | ||
1614 | return TRUE; | |
2bda0e17 KB |
1615 | } |
1616 | ||
19230604 RD |
1617 | |
1618 | ||
edccf428 VZ |
1619 | // ---------------------------------------------------------------------------- |
1620 | // message processing | |
1621 | // ---------------------------------------------------------------------------- | |
1622 | ||
debe6624 | 1623 | bool wxListCtrl::MSWCommand(WXUINT cmd, WXWORD id) |
2bda0e17 | 1624 | { |
0b5efdc7 | 1625 | if (cmd == EN_UPDATE) |
acb62b84 | 1626 | { |
0b5efdc7 VZ |
1627 | wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, id); |
1628 | event.SetEventObject( this ); | |
1629 | ProcessCommand(event); | |
1630 | return TRUE; | |
acb62b84 | 1631 | } |
0b5efdc7 | 1632 | else if (cmd == EN_KILLFOCUS) |
acb62b84 | 1633 | { |
0b5efdc7 VZ |
1634 | wxCommandEvent event(wxEVT_KILL_FOCUS, id); |
1635 | event.SetEventObject( this ); | |
1636 | ProcessCommand(event); | |
1637 | return TRUE; | |
acb62b84 | 1638 | } |
edccf428 VZ |
1639 | else |
1640 | return FALSE; | |
0b5efdc7 VZ |
1641 | } |
1642 | ||
a23fd0e1 | 1643 | bool wxListCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) |
0b5efdc7 | 1644 | { |
bdc72a22 VZ |
1645 | // prepare the event |
1646 | // ----------------- | |
1647 | ||
0b5efdc7 | 1648 | wxListEvent event(wxEVT_NULL, m_windowId); |
648bec3e VZ |
1649 | event.SetEventObject(this); |
1650 | ||
0b5efdc7 | 1651 | wxEventType eventType = wxEVT_NULL; |
225fe9d6 | 1652 | |
bdc72a22 | 1653 | NMHDR *nmhdr = (NMHDR *)lParam; |
225fe9d6 | 1654 | |
d1f2eb1d VZ |
1655 | // if your compiler is as broken as this, you should really change it: this |
1656 | // code is needed for normal operation! #ifdef below is only useful for | |
1657 | // automatic rebuilds which are done with a very old compiler version | |
0cf5b099 | 1658 | #ifdef HDN_BEGINTRACKA |
d1f2eb1d | 1659 | |
11358d39 VZ |
1660 | // check for messages from the header (in report view) |
1661 | HWND hwndHdr = ListView_GetHeader(GetHwnd()); | |
225fe9d6 | 1662 | |
11358d39 VZ |
1663 | // is it a message from the header? |
1664 | if ( nmhdr->hwndFrom == hwndHdr ) | |
acb62b84 | 1665 | { |
00811ff9 | 1666 | HD_NOTIFY *nmHDR = (HD_NOTIFY *)nmhdr; |
0cf5b099 | 1667 | |
11358d39 | 1668 | event.m_itemIndex = -1; |
cb0f56f9 | 1669 | |
11358d39 VZ |
1670 | switch ( nmhdr->code ) |
1671 | { | |
1672 | // yet another comctl32.dll bug: under NT/W2K it sends Unicode | |
1673 | // TRACK messages even to ANSI programs: on my system I get | |
1674 | // HDN_BEGINTRACKW and HDN_ENDTRACKA and no HDN_TRACK at all! | |
1675 | // | |
1676 | // work around is to simply catch both versions and hope that it | |
1677 | // works (why should this message exist in ANSI and Unicode is | |
1678 | // beyond me as it doesn't deal with strings at all...) | |
2b5f62a0 VZ |
1679 | // |
1680 | // note that fr HDN_TRACK another possibility could be to use | |
1681 | // HDN_ITEMCHANGING but it is sent even after HDN_ENDTRACK and when | |
1682 | // something other than the item width changes so we'd have to | |
1683 | // filter out the unwanted events then | |
11358d39 VZ |
1684 | case HDN_BEGINTRACKA: |
1685 | case HDN_BEGINTRACKW: | |
1686 | eventType = wxEVT_COMMAND_LIST_COL_BEGIN_DRAG; | |
1687 | // fall through | |
1688 | ||
1689 | case HDN_TRACKA: | |
1690 | case HDN_TRACKW: | |
1691 | if ( eventType == wxEVT_NULL ) | |
1692 | eventType = wxEVT_COMMAND_LIST_COL_DRAGGING; | |
1693 | // fall through | |
1694 | ||
1695 | case HDN_ENDTRACKA: | |
1696 | case HDN_ENDTRACKW: | |
1697 | if ( eventType == wxEVT_NULL ) | |
1698 | eventType = wxEVT_COMMAND_LIST_COL_END_DRAG; | |
2b5f62a0 VZ |
1699 | |
1700 | event.m_item.m_width = nmHDR->pitem->cxy; | |
11358d39 VZ |
1701 | event.m_col = nmHDR->iItem; |
1702 | break; | |
1703 | ||
1704 | case NM_RCLICK: | |
1705 | { | |
1706 | eventType = wxEVT_COMMAND_LIST_COL_RIGHT_CLICK; | |
1707 | event.m_col = -1; | |
0b5efdc7 | 1708 | |
11358d39 VZ |
1709 | // find the column clicked: we have to search for it |
1710 | // ourselves as the notification message doesn't provide | |
1711 | // this info | |
0b5efdc7 | 1712 | |
11358d39 VZ |
1713 | // where did the click occur? |
1714 | POINT ptClick; | |
1715 | if ( !::GetCursorPos(&ptClick) ) | |
1716 | { | |
1717 | wxLogLastError(_T("GetCursorPos")); | |
1718 | } | |
0b5efdc7 | 1719 | |
11358d39 VZ |
1720 | if ( !::ScreenToClient(hwndHdr, &ptClick) ) |
1721 | { | |
1722 | wxLogLastError(_T("ScreenToClient(listctrl header)")); | |
1723 | } | |
5ea47806 | 1724 | |
11358d39 VZ |
1725 | event.m_pointDrag.x = ptClick.x; |
1726 | event.m_pointDrag.y = ptClick.y; | |
5ea47806 | 1727 | |
11358d39 | 1728 | int colCount = Header_GetItemCount(hwndHdr); |
bdc72a22 | 1729 | |
11358d39 VZ |
1730 | RECT rect; |
1731 | for ( int col = 0; col < colCount; col++ ) | |
1732 | { | |
1733 | if ( Header_GetItemRect(hwndHdr, col, &rect) ) | |
1734 | { | |
1735 | if ( ::PtInRect(&rect, ptClick) ) | |
1736 | { | |
1737 | event.m_col = col; | |
1738 | break; | |
1739 | } | |
1740 | } | |
1741 | } | |
1742 | } | |
1743 | break; | |
5ea47806 | 1744 | |
2b5f62a0 VZ |
1745 | case HDN_GETDISPINFOW: |
1746 | { | |
1747 | LPNMHDDISPINFOW info = (LPNMHDDISPINFOW) lParam; | |
1748 | // This is a fix for a strange bug under XP. | |
1749 | // Normally, info->iItem is a valid index, but | |
1750 | // sometimes this is a silly (large) number | |
1751 | // and when we return FALSE via wxControl::MSWOnNotify | |
1752 | // to indicate that it hasn't yet been processed, | |
1753 | // there's a GPF in Windows. | |
1754 | // By returning TRUE here, we avoid further processing | |
1755 | // of this strange message. | |
1756 | if (info->iItem > GetColumnCount()) | |
1757 | return TRUE; | |
1758 | } | |
1759 | // fall through | |
1760 | ||
11358d39 VZ |
1761 | default: |
1762 | return wxControl::MSWOnNotify(idCtrl, lParam, result); | |
1763 | } | |
1764 | } | |
d1f2eb1d | 1765 | else |
0cf5b099 | 1766 | #endif // defined(HDN_BEGINTRACKA) |
d1f2eb1d | 1767 | if ( nmhdr->hwndFrom == GetHwnd() ) |
11358d39 VZ |
1768 | { |
1769 | // almost all messages use NM_LISTVIEW | |
1770 | NM_LISTVIEW *nmLV = (NM_LISTVIEW *)nmhdr; | |
bdc72a22 | 1771 | |
2b5f62a0 VZ |
1772 | const int iItem = nmLV->iItem; |
1773 | ||
1774 | // set the data event field for all messages for which the system gives | |
1775 | // us a valid NM_LISTVIEW::lParam | |
1776 | switch ( nmLV->hdr.code ) | |
1777 | { | |
1778 | case LVN_BEGINDRAG: | |
1779 | case LVN_BEGINRDRAG: | |
1780 | case LVN_COLUMNCLICK: | |
1781 | case LVN_ITEMCHANGED: | |
1782 | case LVN_ITEMCHANGING: | |
1783 | if ( iItem != -1 ) | |
1784 | { | |
1785 | wxListItemInternalData *internaldata = | |
1786 | (wxListItemInternalData *) nmLV->lParam; | |
1787 | ||
1788 | if ( internaldata ) | |
1789 | event.m_item.m_data = internaldata->lParam; | |
1790 | } | |
1791 | ||
1792 | default: | |
1793 | // fall through | |
1794 | ; | |
1795 | } | |
bdc72a22 | 1796 | |
11358d39 VZ |
1797 | switch ( nmhdr->code ) |
1798 | { | |
1799 | case LVN_BEGINRDRAG: | |
1800 | eventType = wxEVT_COMMAND_LIST_BEGIN_RDRAG; | |
1801 | // fall through | |
7bf1474a | 1802 | |
11358d39 VZ |
1803 | case LVN_BEGINDRAG: |
1804 | if ( eventType == wxEVT_NULL ) | |
1805 | { | |
1806 | eventType = wxEVT_COMMAND_LIST_BEGIN_DRAG; | |
1807 | } | |
bdc72a22 | 1808 | |
2b5f62a0 | 1809 | event.m_itemIndex = iItem; |
11358d39 VZ |
1810 | event.m_pointDrag.x = nmLV->ptAction.x; |
1811 | event.m_pointDrag.y = nmLV->ptAction.y; | |
1812 | break; | |
1813 | ||
8c21905b VS |
1814 | // NB: we have to handle both *A and *W versions here because some |
1815 | // versions of comctl32.dll send ANSI message to an Unicode app | |
1816 | case LVN_BEGINLABELEDITA: | |
11358d39 VZ |
1817 | { |
1818 | eventType = wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT; | |
8c21905b VS |
1819 | wxLV_ITEM item(((LV_DISPINFOA *)lParam)->item); |
1820 | wxConvertFromMSWListItem(GetHwnd(), event.m_item, item); | |
1821 | event.m_itemIndex = event.m_item.m_itemId; | |
1822 | } | |
1823 | break; | |
1824 | case LVN_BEGINLABELEDITW: | |
1825 | { | |
1826 | eventType = wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT; | |
1827 | wxLV_ITEM item(((LV_DISPINFOW *)lParam)->item); | |
1828 | wxConvertFromMSWListItem(GetHwnd(), event.m_item, item); | |
1829 | event.m_itemIndex = event.m_item.m_itemId; | |
1830 | } | |
1831 | break; | |
1832 | ||
1833 | case LVN_ENDLABELEDITA: | |
1834 | { | |
1835 | eventType = wxEVT_COMMAND_LIST_END_LABEL_EDIT; | |
1836 | wxLV_ITEM item(((LV_DISPINFOA *)lParam)->item); | |
1837 | wxConvertFromMSWListItem(NULL, event.m_item, item); | |
73d8c5fd | 1838 | if ( ((LV_ITEM)item).pszText == NULL || |
8c21905b VS |
1839 | ((LV_ITEM)item).iItem == -1 ) |
1840 | return FALSE; | |
1841 | ||
1842 | event.m_itemIndex = event.m_item.m_itemId; | |
1843 | } | |
1844 | break; | |
1845 | case LVN_ENDLABELEDITW: | |
1846 | { | |
1847 | eventType = wxEVT_COMMAND_LIST_END_LABEL_EDIT; | |
1848 | wxLV_ITEM item(((LV_DISPINFOW *)lParam)->item); | |
1849 | wxConvertFromMSWListItem(NULL, event.m_item, item); | |
73d8c5fd | 1850 | if ( ((LV_ITEM)item).pszText == NULL || |
8c21905b VS |
1851 | ((LV_ITEM)item).iItem == -1 ) |
1852 | return FALSE; | |
1853 | ||
11358d39 VZ |
1854 | event.m_itemIndex = event.m_item.m_itemId; |
1855 | } | |
1856 | break; | |
edccf428 | 1857 | |
11358d39 VZ |
1858 | case LVN_COLUMNCLICK: |
1859 | eventType = wxEVT_COMMAND_LIST_COL_CLICK; | |
1860 | event.m_itemIndex = -1; | |
1861 | event.m_col = nmLV->iSubItem; | |
1862 | break; | |
bdc72a22 | 1863 | |
11358d39 VZ |
1864 | case LVN_DELETEALLITEMS: |
1865 | eventType = wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS; | |
1866 | event.m_itemIndex = -1; | |
11358d39 VZ |
1867 | break; |
1868 | ||
1869 | case LVN_DELETEITEM: | |
1870 | eventType = wxEVT_COMMAND_LIST_DELETE_ITEM; | |
2b5f62a0 | 1871 | event.m_itemIndex = iItem; |
7cf46fdb | 1872 | // delete the assoicated internal data |
2b5f62a0 | 1873 | wxDeleteInternalData(this, iItem); |
11358d39 VZ |
1874 | break; |
1875 | ||
11358d39 VZ |
1876 | case LVN_SETDISPINFO: |
1877 | { | |
1878 | eventType = wxEVT_COMMAND_LIST_SET_INFO; | |
1879 | LV_DISPINFO *info = (LV_DISPINFO *)lParam; | |
1880 | wxConvertFromMSWListItem(GetHwnd(), event.m_item, info->item); | |
1881 | } | |
1882 | break; | |
1883 | ||
1884 | case LVN_INSERTITEM: | |
1885 | eventType = wxEVT_COMMAND_LIST_INSERT_ITEM; | |
2b5f62a0 | 1886 | event.m_itemIndex = iItem; |
11358d39 | 1887 | break; |
edccf428 | 1888 | |
11358d39 | 1889 | case LVN_ITEMCHANGED: |
648bec3e VZ |
1890 | // we translate this catch all message into more interesting |
1891 | // (and more easy to process) wxWindows events | |
1892 | ||
2b5f62a0 VZ |
1893 | // first of all, we deal with the state change events only and |
1894 | // only for valid items (item == -1 for the virtual list | |
1895 | // control) | |
1896 | if ( nmLV->uChanged & LVIF_STATE && iItem != -1 ) | |
11358d39 | 1897 | { |
648bec3e VZ |
1898 | // temp vars for readability |
1899 | const UINT stOld = nmLV->uOldState; | |
1900 | const UINT stNew = nmLV->uNewState; | |
1901 | ||
2b5f62a0 VZ |
1902 | event.m_item.SetId(iItem); |
1903 | event.m_item.SetMask(wxLIST_MASK_TEXT | | |
1904 | wxLIST_MASK_IMAGE | | |
1905 | wxLIST_MASK_DATA); | |
1906 | GetItem(event.m_item); | |
1907 | ||
648bec3e VZ |
1908 | // has the focus changed? |
1909 | if ( !(stOld & LVIS_FOCUSED) && (stNew & LVIS_FOCUSED) ) | |
1910 | { | |
1911 | eventType = wxEVT_COMMAND_LIST_ITEM_FOCUSED; | |
2b5f62a0 | 1912 | event.m_itemIndex = iItem; |
648bec3e VZ |
1913 | } |
1914 | ||
1915 | if ( (stNew & LVIS_SELECTED) != (stOld & LVIS_SELECTED) ) | |
1916 | { | |
1917 | if ( eventType != wxEVT_NULL ) | |
1918 | { | |
1919 | // focus and selection have both changed: send the | |
1920 | // focus event from here and the selection one | |
1921 | // below | |
1922 | event.SetEventType(eventType); | |
1923 | (void)GetEventHandler()->ProcessEvent(event); | |
1924 | } | |
1925 | else // no focus event to send | |
1926 | { | |
1927 | // then need to set m_itemIndex as it wasn't done | |
1928 | // above | |
2b5f62a0 | 1929 | event.m_itemIndex = iItem; |
648bec3e VZ |
1930 | } |
1931 | ||
1932 | eventType = stNew & LVIS_SELECTED | |
1933 | ? wxEVT_COMMAND_LIST_ITEM_SELECTED | |
1934 | : wxEVT_COMMAND_LIST_ITEM_DESELECTED; | |
1935 | } | |
edccf428 | 1936 | } |
648bec3e VZ |
1937 | |
1938 | if ( eventType == wxEVT_NULL ) | |
edccf428 | 1939 | { |
648bec3e | 1940 | // not an interesting event for us |
11358d39 | 1941 | return FALSE; |
edccf428 | 1942 | } |
648bec3e | 1943 | |
11358d39 | 1944 | break; |
225fe9d6 | 1945 | |
11358d39 VZ |
1946 | case LVN_KEYDOWN: |
1947 | { | |
1948 | LV_KEYDOWN *info = (LV_KEYDOWN *)lParam; | |
1949 | WORD wVKey = info->wVKey; | |
1950 | ||
1951 | // get the current selection | |
1952 | long lItem = GetNextItem(-1, | |
1953 | wxLIST_NEXT_ALL, | |
1954 | wxLIST_STATE_SELECTED); | |
1955 | ||
1956 | // <Enter> or <Space> activate the selected item if any (but | |
1957 | // not with Shift and/or Ctrl as then they have a predefined | |
1958 | // meaning for the list view) | |
1959 | if ( lItem != -1 && | |
1960 | (wVKey == VK_RETURN || wVKey == VK_SPACE) && | |
1961 | !(wxIsShiftDown() || wxIsCtrlDown()) ) | |
1962 | { | |
1963 | eventType = wxEVT_COMMAND_LIST_ITEM_ACTIVATED; | |
1964 | } | |
1965 | else | |
1966 | { | |
1967 | eventType = wxEVT_COMMAND_LIST_KEY_DOWN; | |
185d0094 VZ |
1968 | |
1969 | // wxCharCodeMSWToWX() returns 0 if the key is an ASCII | |
1970 | // value which should be used as is | |
1971 | int code = wxCharCodeMSWToWX(wVKey); | |
1972 | event.m_code = code ? code : wVKey; | |
11358d39 | 1973 | } |
7db91489 | 1974 | |
11358d39 VZ |
1975 | event.m_itemIndex = |
1976 | event.m_item.m_itemId = lItem; | |
1977 | ||
1978 | if ( lItem != -1 ) | |
1979 | { | |
1980 | // fill the other fields too | |
1981 | event.m_item.m_text = GetItemText(lItem); | |
1982 | event.m_item.m_data = GetItemData(lItem); | |
1983 | } | |
1984 | } | |
1985 | break; | |
1986 | ||
1987 | case NM_DBLCLK: | |
1988 | // if the user processes it in wxEVT_COMMAND_LEFT_CLICK(), don't do | |
1989 | // anything else | |
1990 | if ( wxControl::MSWOnNotify(idCtrl, lParam, result) ) | |
f6bcfd97 | 1991 | { |
11358d39 | 1992 | return TRUE; |
f6bcfd97 | 1993 | } |
edccf428 | 1994 | |
11358d39 VZ |
1995 | // else translate it into wxEVT_COMMAND_LIST_ITEM_ACTIVATED event |
1996 | // if it happened on an item (and not on empty place) | |
2b5f62a0 | 1997 | if ( iItem == -1 ) |
11358d39 VZ |
1998 | { |
1999 | // not on item | |
2000 | return FALSE; | |
2001 | } | |
edccf428 | 2002 | |
11358d39 | 2003 | eventType = wxEVT_COMMAND_LIST_ITEM_ACTIVATED; |
2b5f62a0 VZ |
2004 | event.m_itemIndex = iItem; |
2005 | event.m_item.m_text = GetItemText(iItem); | |
2006 | event.m_item.m_data = GetItemData(iItem); | |
11358d39 | 2007 | break; |
225fe9d6 | 2008 | |
11358d39 | 2009 | case NM_RCLICK: |
225fe9d6 VZ |
2010 | // if the user processes it in wxEVT_COMMAND_RIGHT_CLICK(), |
2011 | // don't do anything else | |
2012 | if ( wxControl::MSWOnNotify(idCtrl, lParam, result) ) | |
2013 | { | |
2014 | return TRUE; | |
2015 | } | |
cb0f56f9 | 2016 | |
225fe9d6 VZ |
2017 | // else translate it into wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK event |
2018 | LV_HITTESTINFO lvhti; | |
2019 | wxZeroMemory(lvhti); | |
11c7d5b6 | 2020 | |
225fe9d6 VZ |
2021 | ::GetCursorPos(&(lvhti.pt)); |
2022 | ::ScreenToClient(GetHwnd(),&(lvhti.pt)); | |
2023 | if ( ListView_HitTest(GetHwnd(),&lvhti) != -1 ) | |
cb0f56f9 | 2024 | { |
225fe9d6 VZ |
2025 | if ( lvhti.flags & LVHT_ONITEM ) |
2026 | { | |
2027 | eventType = wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK; | |
2028 | event.m_itemIndex = lvhti.iItem; | |
a1f79c1e VZ |
2029 | event.m_pointDrag.x = lvhti.pt.x; |
2030 | event.m_pointDrag.y = lvhti.pt.y; | |
225fe9d6 | 2031 | } |
cb0f56f9 | 2032 | } |
11358d39 | 2033 | break; |
bdc72a22 | 2034 | |
bf9b6266 | 2035 | #if defined(_WIN32_IE) && _WIN32_IE >= 0x300 \ |
11358d39 VZ |
2036 | && !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 0 ) ) |
2037 | case NM_CUSTOMDRAW: | |
2038 | *result = OnCustomDraw(lParam); | |
63166611 | 2039 | |
11358d39 | 2040 | return TRUE; |
6ecfe2ac | 2041 | #endif // _WIN32_IE >= 0x300 |
0b5efdc7 | 2042 | |
11358d39 VZ |
2043 | case LVN_ODCACHEHINT: |
2044 | { | |
2045 | const NM_CACHEHINT *cacheHint = (NM_CACHEHINT *)lParam; | |
614391dc | 2046 | |
11358d39 | 2047 | eventType = wxEVT_COMMAND_LIST_CACHE_HINT; |
e623926d | 2048 | |
11358d39 VZ |
2049 | // we get some really stupid cache hints like ones for items in |
2050 | // range 0..0 for an empty control or, after deleting an item, | |
2051 | // for items in invalid range - filter this garbage out | |
2052 | if ( cacheHint->iFrom < cacheHint->iTo ) | |
2053 | { | |
2054 | event.m_oldItemIndex = cacheHint->iFrom; | |
e623926d | 2055 | |
11358d39 VZ |
2056 | long iMax = GetItemCount(); |
2057 | event.m_itemIndex = cacheHint->iTo < iMax ? cacheHint->iTo | |
2058 | : iMax - 1; | |
2059 | } | |
2060 | else | |
2061 | { | |
2062 | return FALSE; | |
2063 | } | |
e623926d | 2064 | } |
11358d39 | 2065 | break; |
614391dc | 2066 | |
11358d39 VZ |
2067 | case LVN_GETDISPINFO: |
2068 | if ( IsVirtual() ) | |
2069 | { | |
2070 | LV_DISPINFO *info = (LV_DISPINFO *)lParam; | |
98ec9dbe | 2071 | |
11358d39 VZ |
2072 | LV_ITEM& lvi = info->item; |
2073 | long item = lvi.iItem; | |
98ec9dbe | 2074 | |
11358d39 VZ |
2075 | if ( lvi.mask & LVIF_TEXT ) |
2076 | { | |
2077 | wxString text = OnGetItemText(item, lvi.iSubItem); | |
2078 | wxStrncpy(lvi.pszText, text, lvi.cchTextMax); | |
2079 | } | |
98ec9dbe | 2080 | |
244531bc | 2081 | #if defined(_WIN32_IE) && _WIN32_IE >= 0x300 \ |
5145e34f | 2082 | && !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 1 ) ) |
11358d39 VZ |
2083 | if ( lvi.mask & LVIF_IMAGE ) |
2084 | { | |
2085 | lvi.iImage = OnGetItemImage(item); | |
2086 | } | |
244531bc | 2087 | #endif |
98ec9dbe | 2088 | |
11358d39 VZ |
2089 | // a little dose of healthy paranoia: as we never use |
2090 | // LVM_SETCALLBACKMASK we're not supposed to get these ones | |
2091 | wxASSERT_MSG( !(lvi.mask & LVIF_STATE), | |
2092 | _T("we don't support state callbacks yet!") ); | |
98ec9dbe | 2093 | |
11358d39 VZ |
2094 | return TRUE; |
2095 | } | |
2096 | // fall through | |
98ec9dbe | 2097 | |
11358d39 VZ |
2098 | default: |
2099 | return wxControl::MSWOnNotify(idCtrl, lParam, result); | |
2100 | } | |
2101 | } | |
2102 | else | |
2103 | { | |
2104 | // where did this one come from? | |
2105 | return FALSE; | |
acb62b84 VZ |
2106 | } |
2107 | ||
bdc72a22 VZ |
2108 | // process the event |
2109 | // ----------------- | |
2110 | ||
0b5efdc7 | 2111 | event.SetEventType(eventType); |
acb62b84 | 2112 | |
0b5efdc7 VZ |
2113 | if ( !GetEventHandler()->ProcessEvent(event) ) |
2114 | return FALSE; | |
acb62b84 | 2115 | |
bdc72a22 VZ |
2116 | // post processing |
2117 | // --------------- | |
2118 | ||
225fe9d6 | 2119 | switch ( nmhdr->code ) |
acb62b84 | 2120 | { |
6932a32c VZ |
2121 | case LVN_DELETEALLITEMS: |
2122 | // always return TRUE to suppress all additional LVN_DELETEITEM | |
2123 | // notifications - this makes deleting all items from a list ctrl | |
2124 | // much faster | |
2125 | *result = TRUE; | |
2126 | ||
2127 | return TRUE; | |
2128 | ||
8c21905b VS |
2129 | case LVN_ENDLABELEDITA: |
2130 | case LVN_ENDLABELEDITW: | |
614391dc VZ |
2131 | // logic here is inversed compared to all the other messages |
2132 | *result = event.IsAllowed(); | |
2133 | ||
2b5f62a0 VZ |
2134 | // don't keep a stale wxTextCtrl around |
2135 | if ( m_textCtrl ) | |
2136 | { | |
2137 | // EDIT control will be deleted by the list control itself so | |
2138 | // prevent us from deleting it as well | |
2139 | m_textCtrl->SetHWND(0); | |
2140 | m_textCtrl->UnsubclassWin(); | |
2141 | delete m_textCtrl; | |
2142 | m_textCtrl = NULL; | |
2143 | } | |
2144 | ||
614391dc | 2145 | return TRUE; |
acb62b84 | 2146 | } |
acb62b84 | 2147 | |
0b5efdc7 | 2148 | *result = !event.IsAllowed(); |
fd3f686c | 2149 | |
0b5efdc7 | 2150 | return TRUE; |
2bda0e17 KB |
2151 | } |
2152 | ||
63166611 VZ |
2153 | #if defined(_WIN32_IE) && _WIN32_IE >= 0x300 |
2154 | ||
2155 | WXLPARAM wxListCtrl::OnCustomDraw(WXLPARAM lParam) | |
2156 | { | |
2157 | LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)lParam; | |
2158 | NMCUSTOMDRAW& nmcd = lplvcd->nmcd; | |
2159 | switch ( nmcd.dwDrawStage ) | |
2160 | { | |
2161 | case CDDS_PREPAINT: | |
2162 | // if we've got any items with non standard attributes, | |
2163 | // notify us before painting each item | |
2164 | // | |
2165 | // for virtual controls, always suppose that we have attributes as | |
2166 | // there is no way to check for this | |
2167 | return IsVirtual() || m_hasAnyAttr ? CDRF_NOTIFYITEMDRAW | |
2168 | : CDRF_DODEFAULT; | |
2169 | ||
2170 | case CDDS_ITEMPREPAINT: | |
2171 | { | |
2172 | size_t item = (size_t)nmcd.dwItemSpec; | |
a7f560a2 VZ |
2173 | if ( item >= (size_t)GetItemCount() ) |
2174 | { | |
2175 | // we get this message with item == 0 for an empty control, | |
2176 | // we must ignore it as calling OnGetItemAttr() would be | |
2177 | // wrong | |
2178 | return CDRF_DODEFAULT; | |
2179 | } | |
2180 | ||
63166611 VZ |
2181 | wxListItemAttr *attr = |
2182 | IsVirtual() ? OnGetItemAttr(item) | |
6149de71 | 2183 | : wxGetInternalDataAttr(this, item); |
63166611 VZ |
2184 | |
2185 | if ( !attr ) | |
2186 | { | |
2187 | // nothing to do for this item | |
2188 | return CDRF_DODEFAULT; | |
2189 | } | |
2190 | ||
2191 | HFONT hFont; | |
2192 | wxColour colText, colBack; | |
2193 | if ( attr->HasFont() ) | |
2194 | { | |
2195 | wxFont font = attr->GetFont(); | |
2196 | hFont = (HFONT)font.GetResourceHandle(); | |
2197 | } | |
2198 | else | |
2199 | { | |
2200 | hFont = 0; | |
2201 | } | |
2202 | ||
2203 | if ( attr->HasTextColour() ) | |
2204 | { | |
2205 | colText = attr->GetTextColour(); | |
2206 | } | |
2207 | else | |
2208 | { | |
2209 | colText = GetTextColour(); | |
2210 | } | |
2211 | ||
2212 | if ( attr->HasBackgroundColour() ) | |
2213 | { | |
2214 | colBack = attr->GetBackgroundColour(); | |
2215 | } | |
2216 | else | |
2217 | { | |
2218 | colBack = GetBackgroundColour(); | |
2219 | } | |
2220 | ||
2221 | lplvcd->clrText = wxColourToRGB(colText); | |
2222 | lplvcd->clrTextBk = wxColourToRGB(colBack); | |
2223 | ||
2224 | // note that if we wanted to set colours for | |
2225 | // individual columns (subitems), we would have | |
2226 | // returned CDRF_NOTIFYSUBITEMREDRAW from here | |
2227 | if ( hFont ) | |
2228 | { | |
2229 | ::SelectObject(nmcd.hdc, hFont); | |
2230 | ||
2231 | return CDRF_NEWFONT; | |
2232 | } | |
2233 | } | |
2234 | // fall through to return CDRF_DODEFAULT | |
2235 | ||
2236 | default: | |
2237 | return CDRF_DODEFAULT; | |
2238 | } | |
2239 | } | |
2240 | ||
2241 | #endif // NM_CUSTOMDRAW supported | |
2242 | ||
2702ed5a JS |
2243 | // Necessary for drawing hrules and vrules, if specified |
2244 | void wxListCtrl::OnPaint(wxPaintEvent& event) | |
2245 | { | |
2246 | wxPaintDC dc(this); | |
2247 | ||
2248 | wxControl::OnPaint(event); | |
2249 | ||
2250 | // Reset the device origin since it may have been set | |
2251 | dc.SetDeviceOrigin(0, 0); | |
2252 | ||
2253 | bool drawHRules = ((GetWindowStyle() & wxLC_HRULES) != 0); | |
2254 | bool drawVRules = ((GetWindowStyle() & wxLC_VRULES) != 0); | |
2255 | ||
2256 | if (!drawHRules && !drawVRules) | |
2257 | return; | |
2258 | if ((GetWindowStyle() & wxLC_REPORT) == 0) | |
2259 | return; | |
2260 | ||
a756f210 | 2261 | wxPen pen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT), 1, wxSOLID); |
2702ed5a JS |
2262 | dc.SetPen(pen); |
2263 | dc.SetBrush(* wxTRANSPARENT_BRUSH); | |
2264 | ||
2265 | wxSize clientSize = GetClientSize(); | |
2266 | wxRect itemRect; | |
2267 | int cy=0; | |
2268 | ||
2702ed5a JS |
2269 | int itemCount = GetItemCount(); |
2270 | int i; | |
625cb8c0 | 2271 | if (drawHRules) |
2702ed5a | 2272 | { |
6443de02 RD |
2273 | long top = GetTopItem(); |
2274 | for (i = top; i < top + GetCountPerPage() + 1; i++) | |
2702ed5a | 2275 | { |
625cb8c0 | 2276 | if (GetItemRect(i, itemRect)) |
ca286917 | 2277 | { |
625cb8c0 RD |
2278 | cy = itemRect.GetTop(); |
2279 | if (i != 0) // Don't draw the first one | |
2280 | { | |
2281 | dc.DrawLine(0, cy, clientSize.x, cy); | |
2282 | } | |
2283 | // Draw last line | |
2cefcb34 | 2284 | if (i == itemCount - 1) |
625cb8c0 RD |
2285 | { |
2286 | cy = itemRect.GetBottom(); | |
2287 | dc.DrawLine(0, cy, clientSize.x, cy); | |
2288 | } | |
2702ed5a JS |
2289 | } |
2290 | } | |
2291 | } | |
2cefcb34 | 2292 | i = itemCount - 1; |
2702ed5a JS |
2293 | if (drawVRules && (i > -1)) |
2294 | { | |
2295 | wxRect firstItemRect; | |
2296 | GetItemRect(0, firstItemRect); | |
2297 | ||
2298 | if (GetItemRect(i, itemRect)) | |
2299 | { | |
2300 | int col; | |
2301 | int x = itemRect.GetX(); | |
2302 | for (col = 0; col < GetColumnCount(); col++) | |
2303 | { | |
2304 | int colWidth = GetColumnWidth(col); | |
2305 | x += colWidth ; | |
e7d073c3 | 2306 | dc.DrawLine(x-1, firstItemRect.GetY() - 2, x-1, itemRect.GetBottom()); |
2702ed5a JS |
2307 | } |
2308 | } | |
2309 | } | |
2310 | } | |
2311 | ||
98ec9dbe VZ |
2312 | // ---------------------------------------------------------------------------- |
2313 | // virtual list controls | |
2314 | // ---------------------------------------------------------------------------- | |
2315 | ||
d699f48b | 2316 | wxString wxListCtrl::OnGetItemText(long WXUNUSED(item), long WXUNUSED(col)) const |
98ec9dbe VZ |
2317 | { |
2318 | // this is a pure virtual function, in fact - which is not really pure | |
2319 | // because the controls which are not virtual don't need to implement it | |
2320 | wxFAIL_MSG( _T("not supposed to be called") ); | |
2321 | ||
2322 | return wxEmptyString; | |
2323 | } | |
2324 | ||
d699f48b | 2325 | int wxListCtrl::OnGetItemImage(long WXUNUSED(item)) const |
98ec9dbe VZ |
2326 | { |
2327 | // same as above | |
2328 | wxFAIL_MSG( _T("not supposed to be called") ); | |
2329 | ||
2330 | return -1; | |
2331 | } | |
2332 | ||
d699f48b | 2333 | wxListItemAttr *wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item)) const |
6c02c329 | 2334 | { |
63166611 | 2335 | wxASSERT_MSG( item >= 0 && item < GetItemCount(), |
6c02c329 VZ |
2336 | _T("invalid item index in OnGetItemAttr()") ); |
2337 | ||
2338 | // no attributes by default | |
2339 | return NULL; | |
2340 | } | |
2341 | ||
98ec9dbe VZ |
2342 | void wxListCtrl::SetItemCount(long count) |
2343 | { | |
2344 | wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") ); | |
2345 | ||
2346 | if ( !::SendMessage(GetHwnd(), LVM_SETITEMCOUNT, (WPARAM)count, 0) ) | |
2347 | { | |
2348 | wxLogLastError(_T("ListView_SetItemCount")); | |
2349 | } | |
2350 | } | |
2351 | ||
a7f560a2 VZ |
2352 | void wxListCtrl::RefreshItem(long item) |
2353 | { | |
2d33aec9 VZ |
2354 | // strangely enough, ListView_Update() results in much more flicker here |
2355 | // than a dumb Refresh() -- why? | |
2356 | #if 0 | |
a7f560a2 VZ |
2357 | if ( !ListView_Update(GetHwnd(), item) ) |
2358 | { | |
2359 | wxLogLastError(_T("ListView_Update")); | |
2360 | } | |
2d33aec9 VZ |
2361 | #else // 1 |
2362 | wxRect rect; | |
2363 | GetItemRect(item, rect); | |
2364 | RefreshRect(rect); | |
2365 | #endif // 0/1 | |
a7f560a2 VZ |
2366 | } |
2367 | ||
2368 | void wxListCtrl::RefreshItems(long itemFrom, long itemTo) | |
2369 | { | |
d0debf52 VZ |
2370 | wxRect rect1, rect2; |
2371 | GetItemRect(itemFrom, rect1); | |
2372 | GetItemRect(itemTo, rect2); | |
2373 | ||
2374 | wxRect rect = rect1; | |
2375 | rect.height = rect2.GetBottom() - rect1.GetTop(); | |
2376 | ||
2377 | RefreshRect(rect); | |
a7f560a2 VZ |
2378 | } |
2379 | ||
6149de71 | 2380 | static wxListItemInternalData *wxGetInternalData(HWND hwnd, long itemId) |
7cf46fdb VZ |
2381 | { |
2382 | LV_ITEM it; | |
2383 | it.mask = LVIF_PARAM; | |
2384 | it.iItem = itemId; | |
2385 | ||
2386 | bool success = ListView_GetItem(hwnd, &it) != 0; | |
2387 | if (success) | |
2388 | return (wxListItemInternalData *) it.lParam; | |
2389 | else | |
2390 | return NULL; | |
2391 | }; | |
2392 | ||
6149de71 | 2393 | static wxListItemInternalData *wxGetInternalData(wxListCtrl *ctl, long itemId) |
7cf46fdb | 2394 | { |
6149de71 | 2395 | return wxGetInternalData((HWND) ctl->GetHWND(), itemId); |
7cf46fdb VZ |
2396 | }; |
2397 | ||
6149de71 | 2398 | static wxListItemAttr *wxGetInternalDataAttr(wxListCtrl *ctl, long itemId) |
7cf46fdb | 2399 | { |
6149de71 | 2400 | wxListItemInternalData *data = wxGetInternalData(ctl, itemId); |
7cf46fdb VZ |
2401 | if (data) |
2402 | return data->attr; | |
2403 | else | |
2404 | return NULL; | |
2405 | }; | |
2406 | ||
6149de71 RD |
2407 | static void wxDeleteInternalData(wxListCtrl* ctl, long itemId) |
2408 | { | |
2409 | wxListItemInternalData *data = wxGetInternalData(ctl, itemId); | |
2410 | if (data) | |
2411 | { | |
2412 | delete data; | |
2413 | LV_ITEM item; | |
2414 | memset(&item, 0, sizeof(item)); | |
2415 | item.iItem = itemId; | |
2416 | item.mask = LVIF_PARAM; | |
2417 | item.lParam = (LPARAM) 0; | |
2418 | ListView_SetItem((HWND)ctl->GetHWND(), &item); | |
2419 | } | |
2420 | } | |
7cf46fdb | 2421 | |
8dff2b5c VZ |
2422 | static void wxConvertFromMSWListItem(HWND hwndListCtrl, |
2423 | wxListItem& info, | |
2424 | LV_ITEM& lvItem) | |
2bda0e17 | 2425 | { |
73d8c5fd | 2426 | wxListItemInternalData *internaldata = |
7cf46fdb VZ |
2427 | (wxListItemInternalData *) lvItem.lParam; |
2428 | ||
2429 | if (internaldata) | |
2430 | info.m_data = internaldata->lParam; | |
2431 | ||
0b5efdc7 VZ |
2432 | info.m_mask = 0; |
2433 | info.m_state = 0; | |
2434 | info.m_stateMask = 0; | |
2435 | info.m_itemId = lvItem.iItem; | |
acb62b84 | 2436 | |
0b5efdc7 | 2437 | long oldMask = lvItem.mask; |
acb62b84 | 2438 | |
0b5efdc7 | 2439 | bool needText = FALSE; |
8dff2b5c | 2440 | if (hwndListCtrl != 0) |
acb62b84 | 2441 | { |
0b5efdc7 VZ |
2442 | if ( lvItem.mask & LVIF_TEXT ) |
2443 | needText = FALSE; | |
2444 | else | |
2445 | needText = TRUE; | |
acb62b84 | 2446 | |
0b5efdc7 VZ |
2447 | if ( needText ) |
2448 | { | |
837e5743 | 2449 | lvItem.pszText = new wxChar[513]; |
0b5efdc7 VZ |
2450 | lvItem.cchTextMax = 512; |
2451 | } | |
edccf428 | 2452 | lvItem.mask |= LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM; |
8dff2b5c | 2453 | ::SendMessage(hwndListCtrl, LVM_GETITEM, 0, (LPARAM)& lvItem); |
0b5efdc7 | 2454 | } |
acb62b84 | 2455 | |
0b5efdc7 | 2456 | if ( lvItem.mask & LVIF_STATE ) |
acb62b84 | 2457 | { |
0b5efdc7 VZ |
2458 | info.m_mask |= wxLIST_MASK_STATE; |
2459 | ||
2460 | if ( lvItem.stateMask & LVIS_CUT) | |
2461 | { | |
edccf428 | 2462 | info.m_stateMask |= wxLIST_STATE_CUT; |
0b5efdc7 | 2463 | if ( lvItem.state & LVIS_CUT ) |
edccf428 | 2464 | info.m_state |= wxLIST_STATE_CUT; |
0b5efdc7 VZ |
2465 | } |
2466 | if ( lvItem.stateMask & LVIS_DROPHILITED) | |
2467 | { | |
edccf428 | 2468 | info.m_stateMask |= wxLIST_STATE_DROPHILITED; |
0b5efdc7 | 2469 | if ( lvItem.state & LVIS_DROPHILITED ) |
edccf428 | 2470 | info.m_state |= wxLIST_STATE_DROPHILITED; |
0b5efdc7 VZ |
2471 | } |
2472 | if ( lvItem.stateMask & LVIS_FOCUSED) | |
2473 | { | |
edccf428 | 2474 | info.m_stateMask |= wxLIST_STATE_FOCUSED; |
0b5efdc7 | 2475 | if ( lvItem.state & LVIS_FOCUSED ) |
edccf428 | 2476 | info.m_state |= wxLIST_STATE_FOCUSED; |
0b5efdc7 VZ |
2477 | } |
2478 | if ( lvItem.stateMask & LVIS_SELECTED) | |
2479 | { | |
edccf428 | 2480 | info.m_stateMask |= wxLIST_STATE_SELECTED; |
0b5efdc7 | 2481 | if ( lvItem.state & LVIS_SELECTED ) |
edccf428 | 2482 | info.m_state |= wxLIST_STATE_SELECTED; |
0b5efdc7 | 2483 | } |
acb62b84 | 2484 | } |
0b5efdc7 VZ |
2485 | |
2486 | if ( lvItem.mask & LVIF_TEXT ) | |
acb62b84 | 2487 | { |
0b5efdc7 VZ |
2488 | info.m_mask |= wxLIST_MASK_TEXT; |
2489 | info.m_text = lvItem.pszText; | |
acb62b84 | 2490 | } |
0b5efdc7 | 2491 | if ( lvItem.mask & LVIF_IMAGE ) |
acb62b84 | 2492 | { |
0b5efdc7 VZ |
2493 | info.m_mask |= wxLIST_MASK_IMAGE; |
2494 | info.m_image = lvItem.iImage; | |
acb62b84 | 2495 | } |
0b5efdc7 VZ |
2496 | if ( lvItem.mask & LVIF_PARAM ) |
2497 | info.m_mask |= wxLIST_MASK_DATA; | |
2498 | if ( lvItem.mask & LVIF_DI_SETITEM ) | |
2499 | info.m_mask |= wxLIST_SET_ITEM; | |
2500 | info.m_col = lvItem.iSubItem; | |
2501 | ||
2502 | if (needText) | |
acb62b84 | 2503 | { |
0b5efdc7 VZ |
2504 | if (lvItem.pszText) |
2505 | delete[] lvItem.pszText; | |
acb62b84 | 2506 | } |
edccf428 | 2507 | lvItem.mask = oldMask; |
2bda0e17 KB |
2508 | } |
2509 | ||
8dff2b5c VZ |
2510 | static void wxConvertToMSWFlags(long state, long stateMask, LV_ITEM& lvItem) |
2511 | { | |
2512 | if (stateMask & wxLIST_STATE_CUT) | |
2513 | { | |
2514 | lvItem.stateMask |= LVIS_CUT; | |
2515 | if (state & wxLIST_STATE_CUT) | |
2516 | lvItem.state |= LVIS_CUT; | |
2517 | } | |
2518 | if (stateMask & wxLIST_STATE_DROPHILITED) | |
2519 | { | |
2520 | lvItem.stateMask |= LVIS_DROPHILITED; | |
2521 | if (state & wxLIST_STATE_DROPHILITED) | |
2522 | lvItem.state |= LVIS_DROPHILITED; | |
2523 | } | |
2524 | if (stateMask & wxLIST_STATE_FOCUSED) | |
2525 | { | |
2526 | lvItem.stateMask |= LVIS_FOCUSED; | |
2527 | if (state & wxLIST_STATE_FOCUSED) | |
2528 | lvItem.state |= LVIS_FOCUSED; | |
2529 | } | |
2530 | if (stateMask & wxLIST_STATE_SELECTED) | |
2531 | { | |
2532 | lvItem.stateMask |= LVIS_SELECTED; | |
2533 | if (state & wxLIST_STATE_SELECTED) | |
2534 | lvItem.state |= LVIS_SELECTED; | |
2535 | } | |
2536 | } | |
2537 | ||
2538 | static void wxConvertToMSWListItem(const wxListCtrl *ctrl, | |
2539 | const wxListItem& info, | |
2540 | LV_ITEM& lvItem) | |
2bda0e17 | 2541 | { |
edccf428 | 2542 | lvItem.iItem = (int) info.m_itemId; |
acb62b84 | 2543 | |
edccf428 | 2544 | lvItem.iImage = info.m_image; |
0b5efdc7 VZ |
2545 | lvItem.stateMask = 0; |
2546 | lvItem.state = 0; | |
2547 | lvItem.mask = 0; | |
2548 | lvItem.iSubItem = info.m_col; | |
acb62b84 | 2549 | |
0b5efdc7 | 2550 | if (info.m_mask & wxLIST_MASK_STATE) |
acb62b84 | 2551 | { |
edccf428 | 2552 | lvItem.mask |= LVIF_STATE; |
8dff2b5c VZ |
2553 | |
2554 | wxConvertToMSWFlags(info.m_state, info.m_stateMask, lvItem); | |
acb62b84 | 2555 | } |
acb62b84 | 2556 | |
0b5efdc7 | 2557 | if (info.m_mask & wxLIST_MASK_TEXT) |
acb62b84 | 2558 | { |
edccf428 | 2559 | lvItem.mask |= LVIF_TEXT; |
0b5efdc7 VZ |
2560 | if ( ctrl->GetWindowStyleFlag() & wxLC_USER_TEXT ) |
2561 | { | |
2562 | lvItem.pszText = LPSTR_TEXTCALLBACK; | |
2563 | } | |
2564 | else | |
2565 | { | |
e421922f VZ |
2566 | // pszText is not const, hence the cast |
2567 | lvItem.pszText = (wxChar *)info.m_text.c_str(); | |
0b5efdc7 VZ |
2568 | if ( lvItem.pszText ) |
2569 | lvItem.cchTextMax = info.m_text.Length(); | |
2570 | else | |
2571 | lvItem.cchTextMax = 0; | |
2572 | } | |
acb62b84 | 2573 | } |
0b5efdc7 | 2574 | if (info.m_mask & wxLIST_MASK_IMAGE) |
edccf428 | 2575 | lvItem.mask |= LVIF_IMAGE; |
2bda0e17 KB |
2576 | } |
2577 | ||
574c939e | 2578 | static void wxConvertToMSWListCol(int WXUNUSED(col), const wxListItem& item, |
6f806543 VZ |
2579 | LV_COLUMN& lvCol) |
2580 | { | |
2581 | wxZeroMemory(lvCol); | |
2582 | ||
2583 | if ( item.m_mask & wxLIST_MASK_TEXT ) | |
2584 | { | |
2585 | lvCol.mask |= LVCF_TEXT; | |
2586 | lvCol.pszText = (wxChar *)item.m_text.c_str(); // cast is safe | |
2587 | } | |
2588 | ||
2589 | if ( item.m_mask & wxLIST_MASK_FORMAT ) | |
2590 | { | |
2591 | lvCol.mask |= LVCF_FMT; | |
2592 | ||
2593 | if ( item.m_format == wxLIST_FORMAT_LEFT ) | |
2594 | lvCol.fmt = LVCFMT_LEFT; | |
2595 | else if ( item.m_format == wxLIST_FORMAT_RIGHT ) | |
2596 | lvCol.fmt = LVCFMT_RIGHT; | |
2597 | else if ( item.m_format == wxLIST_FORMAT_CENTRE ) | |
2598 | lvCol.fmt = LVCFMT_CENTER; | |
2599 | } | |
2600 | ||
2601 | if ( item.m_mask & wxLIST_MASK_WIDTH ) | |
2602 | { | |
2603 | lvCol.mask |= LVCF_WIDTH; | |
2604 | if ( item.m_width == wxLIST_AUTOSIZE) | |
2605 | lvCol.cx = LVSCW_AUTOSIZE; | |
2606 | else if ( item.m_width == wxLIST_AUTOSIZE_USEHEADER) | |
2607 | lvCol.cx = LVSCW_AUTOSIZE_USEHEADER; | |
2608 | else | |
2609 | lvCol.cx = item.m_width; | |
2610 | } | |
2611 | ||
244531bc | 2612 | #if defined(_WIN32_IE) && _WIN32_IE >= 0x300 \ |
5145e34f | 2613 | && !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 1 ) ) |
6f806543 VZ |
2614 | if ( item.m_mask & wxLIST_MASK_IMAGE ) |
2615 | { | |
2616 | if ( wxTheApp->GetComCtl32Version() >= 470 ) | |
2617 | { | |
2618 | lvCol.mask |= LVCF_IMAGE; | |
2619 | lvCol.iImage = item.m_image; | |
2620 | } | |
2621 | //else: it doesn't support item images anyhow | |
2622 | } | |
244531bc | 2623 | #endif |
6f806543 VZ |
2624 | } |
2625 | ||
1e6feb95 | 2626 | #endif // wxUSE_LISTCTRL |