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