]> git.saurik.com Git - wxWidgets.git/blame - src/msw/listctrl.cpp
fatal bug in wxSplitPath fixed
[wxWidgets.git] / src / msw / listctrl.cpp
CommitLineData
2bda0e17
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: listctrl.cpp
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
32#ifndef WX_PRECOMP
0b5efdc7 33 #include "wx/wx.h"
2bda0e17
KB
34#endif
35
edccf428 36#ifdef __WIN95__
2bda0e17
KB
37
38#include "wx/listctrl.h"
f8352807 39#include "wx/log.h"
2bda0e17
KB
40
41#include "wx/msw/private.h"
42
c42404a5 43#ifdef __GNUWIN32_OLD__
edccf428
VZ
44 #include "wx/msw/gnuwin32/extra.h"
45#else
0b5efdc7 46 #include <commctrl.h>
2bda0e17
KB
47#endif
48
bdc72a22
VZ
49#ifndef LVHT_ONITEM
50 #define LVHT_ONITEM \
51 (LVHT_ONITEMICON | LVHT_ONITEMLABEL | LVHT_ONITEMSTATEICON)
52#endif
53
225fe9d6
VZ
54#ifndef LVM_SETEXTENDEDLISTVIEWSTYLE
55 #define LVM_SETEXTENDEDLISTVIEWSTYLE 0x1054
56#endif
57
58#ifndef LVS_EX_FULLROWSELECT
59 #define LVS_EX_FULLROWSELECT 0x00000020
60#endif
61
edccf428
VZ
62// ----------------------------------------------------------------------------
63// private functions
64// ----------------------------------------------------------------------------
2bda0e17
KB
65
66static void wxConvertToMSWListItem(const wxListCtrl *ctrl, wxListItem& info, LV_ITEM& tvItem);
67static void wxConvertFromMSWListItem(const wxListCtrl *ctrl, wxListItem& info, LV_ITEM& tvItem, HWND getFullInfo = 0);
68
edccf428
VZ
69// ----------------------------------------------------------------------------
70// macros
71// ----------------------------------------------------------------------------
72
8f177c8e
VZ
73IMPLEMENT_DYNAMIC_CLASS(wxListCtrl, wxControl)
74IMPLEMENT_DYNAMIC_CLASS(wxListItem, wxObject)
2bda0e17 75
edccf428
VZ
76// ============================================================================
77// implementation
78// ============================================================================
79
8f177c8e
VZ
80// ----------------------------------------------------------------------------
81// wxListEvent
82// ----------------------------------------------------------------------------
83
84void wxListEvent::CopyObject(wxObject& object_dest) const
85{
86 wxListEvent *obj = (wxListEvent *)&object_dest;
87
88 wxNotifyEvent::CopyObject(object_dest);
89
90 obj->m_code = m_code;
91 obj->m_itemIndex = m_itemIndex;
92 obj->m_oldItemIndex = m_oldItemIndex;
93 obj->m_col = m_col;
94 obj->m_cancelled = m_cancelled;
95 obj->m_pointDrag = m_pointDrag;
96 obj->m_item.m_mask = m_item.m_mask;
97 obj->m_item.m_itemId = m_item.m_itemId;
98 obj->m_item.m_col = m_item.m_col;
99 obj->m_item.m_state = m_item.m_state;
100 obj->m_item.m_stateMask = m_item.m_stateMask;
101 obj->m_item.m_text = m_item.m_text;
102 obj->m_item.m_image = m_item.m_image;
103 obj->m_item.m_data = m_item.m_data;
104 obj->m_item.m_format = m_item.m_format;
105 obj->m_item.m_width = m_item.m_width;
106
107 if ( m_item.HasAttributes() )
108 {
109 obj->m_item.SetTextColour(m_item.GetTextColour());
110 obj->m_item.SetBackgroundColour(m_item.GetBackgroundColour());
111 obj->m_item.SetFont(m_item.GetFont());
112 }
113}
114
edccf428
VZ
115// ----------------------------------------------------------------------------
116// wxListCtrl construction
117// ----------------------------------------------------------------------------
118
bdc72a22 119void wxListCtrl::Init()
2bda0e17 120{
0b5efdc7
VZ
121 m_imageListNormal = NULL;
122 m_imageListSmall = NULL;
123 m_imageListState = NULL;
124 m_baseStyle = 0;
2bda0e17 125 m_colCount = 0;
bbcdf8bc 126 m_textCtrl = NULL;
bdc72a22 127 m_hasAnyAttr = FALSE;
2bda0e17
KB
128}
129
0b5efdc7
VZ
130bool wxListCtrl::Create(wxWindow *parent,
131 wxWindowID id,
132 const wxPoint& pos,
133 const wxSize& size,
134 long style,
135 const wxValidator& validator,
136 const wxString& name)
2bda0e17 137{
11b6a93b 138#if wxUSE_VALIDATORS
0b5efdc7 139 SetValidator(validator);
11b6a93b
VZ
140#endif // wxUSE_VALIDATORS
141
0b5efdc7 142 SetName(name);
2bda0e17 143
0b5efdc7
VZ
144 int x = pos.x;
145 int y = pos.y;
146 int width = size.x;
147 int height = size.y;
2bda0e17 148
0b5efdc7 149 m_windowStyle = style;
2bda0e17 150
0b5efdc7 151 SetParent(parent);
2bda0e17 152
0b5efdc7
VZ
153 if (width <= 0)
154 width = 100;
155 if (height <= 0)
156 height = 30;
157 if (x < 0)
158 x = 0;
159 if (y < 0)
160 y = 0;
2bda0e17 161
0b5efdc7 162 m_windowId = (id == -1) ? NewControlId() : id;
2bda0e17 163
edccf428
VZ
164 DWORD wstyle = WS_VISIBLE | WS_CHILD | WS_TABSTOP |
165 LVS_SHAREIMAGELISTS | LVS_SHOWSELALWAYS;
166 if ( wxStyleHasBorder(m_windowStyle) )
167 wstyle |= WS_BORDER;
168 m_baseStyle = wstyle;
169
170 if ( !DoCreateControl(x, y, width, height) )
171 return FALSE;
172
173 if (parent)
174 parent->AddChild(this);
175
176 return TRUE;
177}
178
179bool wxListCtrl::DoCreateControl(int x, int y, int w, int h)
180{
181 DWORD wstyle = m_baseStyle;
2bda0e17 182
0b5efdc7 183 bool want3D;
edccf428 184 WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, &want3D);
2bda0e17 185
0b5efdc7
VZ
186 // Even with extended styles, need to combine with WS_BORDER
187 // for them to look right.
edccf428 188 if ( want3D )
0b5efdc7 189 wstyle |= WS_BORDER;
2bda0e17 190
0b5efdc7
VZ
191 long oldStyle = 0; // Dummy
192 wstyle |= ConvertToMSWStyle(oldStyle, m_windowStyle);
2bda0e17 193
0b5efdc7
VZ
194 // Create the ListView control.
195 m_hWnd = (WXHWND)CreateWindowEx(exStyle,
196 WC_LISTVIEW,
223d09f6 197 wxT(""),
0b5efdc7 198 wstyle,
edccf428
VZ
199 x, y, w, h,
200 GetWinHwnd(GetParent()),
0b5efdc7
VZ
201 (HMENU)m_windowId,
202 wxGetInstance(),
203 NULL);
f8352807 204
edccf428
VZ
205 if ( !m_hWnd )
206 {
225fe9d6
VZ
207 wxLogError(_("Can't create list control window, check "
208 "that comctl32.dll is installed."));
0b5efdc7
VZ
209
210 return FALSE;
211 }
212
213 // for comctl32.dll v 4.70+ we want to have this attribute because it's
214 // prettier (and also because wxGTK does it like this)
225fe9d6 215 if ( (wstyle & LVS_REPORT) && wxTheApp->GetComCtl32Version() >= 470 )
0b5efdc7 216 {
225fe9d6
VZ
217 ::SendMessage(GetHwnd(), LVM_SETEXTENDEDLISTVIEWSTYLE,
218 0, LVS_EX_FULLROWSELECT);
0b5efdc7 219 }
f8352807 220
5aeeab14 221 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW));
edccf428 222 SetForegroundColour(GetParent()->GetForegroundColour());
2bda0e17 223
edccf428 224 SubclassWin(m_hWnd);
2bda0e17 225
0b5efdc7 226 return TRUE;
2bda0e17
KB
227}
228
edccf428
VZ
229void wxListCtrl::UpdateStyle()
230{
231 if ( GetHWND() )
232 {
233 // The new window view style
234 long dummy;
235 DWORD dwStyleNew = ConvertToMSWStyle(dummy, m_windowStyle);
236 dwStyleNew |= m_baseStyle;
237
910484a6 238 // Get the current window style.
edccf428
VZ
239 DWORD dwStyleOld = ::GetWindowLong(GetHwnd(), GWL_STYLE);
240
910484a6 241 // Only set the window style if the view bits have changed.
edccf428
VZ
242 if ( dwStyleOld != dwStyleNew )
243 {
244 ::SetWindowLong(GetHwnd(), GWL_STYLE, dwStyleNew);
245 }
246 }
247}
248
91b4c08d 249void wxListCtrl::FreeAllAttrs(bool dontRecreate)
2bda0e17 250{
d62228a6
VZ
251 if ( m_hasAnyAttr )
252 {
253 for ( wxNode *node = m_attrs.Next(); node; node = m_attrs.Next() )
254 {
255 delete (wxListItemAttr *)node->Data();
256 }
6932a32c
VZ
257
258 m_attrs.Destroy();
91b4c08d
VZ
259 if ( !dontRecreate )
260 {
261 m_attrs.Create(wxKEY_INTEGER, 1000); // just as def ctor
262 }
6932a32c
VZ
263
264 m_hasAnyAttr = FALSE;
d62228a6 265 }
6932a32c 266}
d62228a6 267
6932a32c
VZ
268wxListCtrl::~wxListCtrl()
269{
91b4c08d
VZ
270 FreeAllAttrs(TRUE /* no need to recreate hash any more */);
271
d62228a6 272 if ( m_textCtrl )
bbcdf8bc 273 {
0b5efdc7
VZ
274 m_textCtrl->UnsubclassWin();
275 m_textCtrl->SetHWND(0);
276 delete m_textCtrl;
277 m_textCtrl = NULL;
bbcdf8bc 278 }
2bda0e17
KB
279}
280
edccf428
VZ
281// ----------------------------------------------------------------------------
282// set/get/change style
283// ----------------------------------------------------------------------------
284
2bda0e17 285// Add or remove a single window style
debe6624 286void wxListCtrl::SetSingleStyle(long style, bool add)
2bda0e17 287{
0b5efdc7 288 long flag = GetWindowStyleFlag();
2bda0e17 289
0b5efdc7 290 // Get rid of conflicting styles
acb62b84
VZ
291 if ( add )
292 {
0b5efdc7 293 if ( style & wxLC_MASK_TYPE)
edccf428 294 flag = flag & ~wxLC_MASK_TYPE;
0b5efdc7 295 if ( style & wxLC_MASK_ALIGN )
edccf428 296 flag = flag & ~wxLC_MASK_ALIGN;
0b5efdc7 297 if ( style & wxLC_MASK_SORT )
edccf428 298 flag = flag & ~wxLC_MASK_SORT;
acb62b84 299 }
2bda0e17 300
0b5efdc7
VZ
301 if ( flag & style )
302 {
303 if ( !add )
304 flag -= style;
305 }
306 else
307 {
308 if ( add )
309 {
310 flag |= style;
311 }
312 }
313
314 m_windowStyle = flag;
2bda0e17 315
edccf428 316 UpdateStyle();
2bda0e17
KB
317}
318
319// Set the whole window style
debe6624 320void wxListCtrl::SetWindowStyleFlag(long flag)
2bda0e17 321{
0b5efdc7 322 m_windowStyle = flag;
2bda0e17 323
edccf428 324 UpdateStyle();
2bda0e17
KB
325}
326
0b5efdc7
VZ
327// Can be just a single style, or a bitlist
328long wxListCtrl::ConvertToMSWStyle(long& oldStyle, long style) const
2bda0e17 329{
0b5efdc7
VZ
330 long wstyle = 0;
331 if ( style & wxLC_ICON )
332 {
333 if ( (oldStyle & LVS_TYPEMASK) == LVS_SMALLICON )
334 oldStyle -= LVS_SMALLICON;
335 if ( (oldStyle & LVS_TYPEMASK) == LVS_REPORT )
336 oldStyle -= LVS_REPORT;
337 if ( (oldStyle & LVS_TYPEMASK) == LVS_LIST )
338 oldStyle -= LVS_LIST;
339 wstyle |= LVS_ICON;
340 }
341
342 if ( style & wxLC_SMALL_ICON )
343 {
344 if ( (oldStyle & LVS_TYPEMASK) == LVS_ICON )
345 oldStyle -= LVS_ICON;
346 if ( (oldStyle & LVS_TYPEMASK) == LVS_REPORT )
347 oldStyle -= LVS_REPORT;
348 if ( (oldStyle & LVS_TYPEMASK) == LVS_LIST )
349 oldStyle -= LVS_LIST;
350 wstyle |= LVS_SMALLICON;
351 }
352
353 if ( style & wxLC_LIST )
354 {
355 if ( (oldStyle & LVS_TYPEMASK) == LVS_ICON )
356 oldStyle -= LVS_ICON;
357 if ( (oldStyle & LVS_TYPEMASK) == LVS_REPORT )
358 oldStyle -= LVS_REPORT;
359 if ( (oldStyle & LVS_TYPEMASK) == LVS_SMALLICON )
360 oldStyle -= LVS_SMALLICON;
361 wstyle |= LVS_LIST;
362 }
2bda0e17 363
0b5efdc7
VZ
364 if ( style & wxLC_REPORT )
365 {
366 if ( (oldStyle & LVS_TYPEMASK) == LVS_ICON )
367 oldStyle -= LVS_ICON;
368 if ( (oldStyle & LVS_TYPEMASK) == LVS_LIST )
369 oldStyle -= LVS_LIST;
370 if ( (oldStyle & LVS_TYPEMASK) == LVS_SMALLICON )
371 oldStyle -= LVS_SMALLICON;
372
373 wstyle |= LVS_REPORT;
374 }
2bda0e17 375
0b5efdc7
VZ
376 if ( style & wxLC_ALIGN_LEFT )
377 {
378 if ( oldStyle & LVS_ALIGNTOP )
379 oldStyle -= LVS_ALIGNTOP;
380 wstyle |= LVS_ALIGNLEFT;
381 }
2bda0e17 382
0b5efdc7
VZ
383 if ( style & wxLC_ALIGN_TOP )
384 {
385 if ( oldStyle & LVS_ALIGNLEFT )
386 oldStyle -= LVS_ALIGNLEFT;
387 wstyle |= LVS_ALIGNTOP;
388 }
2bda0e17 389
0b5efdc7
VZ
390 if ( style & wxLC_AUTOARRANGE )
391 wstyle |= LVS_AUTOARRANGE;
2bda0e17 392
0b5efdc7
VZ
393 // Apparently, no such style (documentation wrong?)
394 /*
395 if ( style & wxLC_BUTTON )
396 wstyle |= LVS_BUTTON;
397 */
2bda0e17 398
0b5efdc7
VZ
399 if ( style & wxLC_NO_SORT_HEADER )
400 wstyle |= LVS_NOSORTHEADER;
2bda0e17 401
0b5efdc7
VZ
402 if ( style & wxLC_NO_HEADER )
403 wstyle |= LVS_NOCOLUMNHEADER;
404
405 if ( style & wxLC_EDIT_LABELS )
406 wstyle |= LVS_EDITLABELS;
407
408 if ( style & wxLC_SINGLE_SEL )
409 wstyle |= LVS_SINGLESEL;
410
411 if ( style & wxLC_SORT_ASCENDING )
412 {
413 if ( oldStyle & LVS_SORTDESCENDING )
414 oldStyle -= LVS_SORTDESCENDING;
415 wstyle |= LVS_SORTASCENDING;
416 }
417
418 if ( style & wxLC_SORT_DESCENDING )
419 {
420 if ( oldStyle & LVS_SORTASCENDING )
421 oldStyle -= LVS_SORTASCENDING;
422 wstyle |= LVS_SORTDESCENDING;
423 }
424
425 return wstyle;
2bda0e17
KB
426}
427
edccf428
VZ
428// ----------------------------------------------------------------------------
429// accessors
430// ----------------------------------------------------------------------------
431
91b4c08d
VZ
432// Sets the foreground, i.e. text, colour
433bool wxListCtrl::SetForegroundColour(const wxColour& col)
434{
435 if ( !wxWindow::SetForegroundColour(col) )
436 return FALSE;
437
438 ListView_SetTextColor(GetHwnd(), wxColourToRGB(col));
439
440 return TRUE;
441}
442
443// Sets the background colour
cc2b7472 444bool wxListCtrl::SetBackgroundColour(const wxColour& col)
2bda0e17 445{
cc2b7472
VZ
446 if ( !wxWindow::SetBackgroundColour(col) )
447 return FALSE;
2bda0e17 448
91b4c08d
VZ
449 // we set the same colour for both the "empty" background and the items
450 // background
451 COLORREF color = wxColourToRGB(col);
452 ListView_SetBkColor(GetHwnd(), color);
453 ListView_SetTextBkColor(GetHwnd(), color);
cc2b7472
VZ
454
455 return TRUE;
2bda0e17
KB
456}
457
458// Gets information about this column
debe6624 459bool wxListCtrl::GetColumn(int col, wxListItem& item) const
2bda0e17 460{
0b5efdc7
VZ
461 LV_COLUMN lvCol;
462 lvCol.mask = 0;
463 lvCol.fmt = 0;
464 lvCol.pszText = NULL;
465
466 if ( item.m_mask & wxLIST_MASK_TEXT )
467 {
468 lvCol.mask |= LVCF_TEXT;
837e5743 469 lvCol.pszText = new wxChar[513];
0b5efdc7
VZ
470 lvCol.cchTextMax = 512;
471 }
472
edccf428 473 bool success = (ListView_GetColumn(GetHwnd(), col, & lvCol) != 0);
0b5efdc7
VZ
474
475 // item.m_subItem = lvCol.iSubItem;
476 item.m_width = lvCol.cx;
477
478 if ( (item.m_mask & wxLIST_MASK_TEXT) && lvCol.pszText )
479 {
480 item.m_text = lvCol.pszText;
481 delete[] lvCol.pszText;
482 }
483
484 if ( item.m_mask & wxLIST_MASK_FORMAT )
485 {
486 if (lvCol.fmt == LVCFMT_LEFT)
487 item.m_format = wxLIST_FORMAT_LEFT;
488 else if (lvCol.fmt == LVCFMT_RIGHT)
489 item.m_format = wxLIST_FORMAT_RIGHT;
490 else if (lvCol.fmt == LVCFMT_CENTER)
491 item.m_format = wxLIST_FORMAT_CENTRE;
2bda0e17
KB
492 }
493
0b5efdc7 494 return success;
2bda0e17
KB
495}
496
497// Sets information about this column
debe6624 498bool wxListCtrl::SetColumn(int col, wxListItem& item)
2bda0e17 499{
0b5efdc7
VZ
500 LV_COLUMN lvCol;
501 lvCol.mask = 0;
502 lvCol.fmt = 0;
503 lvCol.pszText = NULL;
504
505 if ( item.m_mask & wxLIST_MASK_TEXT )
506 {
507 lvCol.mask |= LVCF_TEXT;
508 lvCol.pszText = WXSTRINGCAST item.m_text;
509 lvCol.cchTextMax = 0; // Ignored
510 }
511 if ( item.m_mask & wxLIST_MASK_FORMAT )
512 {
513 lvCol.mask |= LVCF_FMT;
514
515 if ( item.m_format == wxLIST_FORMAT_LEFT )
516 lvCol.fmt = LVCFMT_LEFT;
517 if ( item.m_format == wxLIST_FORMAT_RIGHT )
518 lvCol.fmt = LVCFMT_RIGHT;
519 if ( item.m_format == wxLIST_FORMAT_CENTRE )
520 lvCol.fmt = LVCFMT_CENTER;
2bda0e17
KB
521 }
522
0b5efdc7
VZ
523 if ( item.m_mask & wxLIST_MASK_WIDTH )
524 {
525 lvCol.mask |= LVCF_WIDTH;
526 lvCol.cx = item.m_width;
2bda0e17 527
0b5efdc7
VZ
528 if ( lvCol.cx == wxLIST_AUTOSIZE)
529 lvCol.cx = LVSCW_AUTOSIZE;
530 else if ( lvCol.cx == wxLIST_AUTOSIZE_USEHEADER)
531 lvCol.cx = LVSCW_AUTOSIZE_USEHEADER;
532 }
533 lvCol.mask |= LVCF_SUBITEM;
534 lvCol.iSubItem = col;
edccf428 535 return (ListView_SetColumn(GetHwnd(), col, & lvCol) != 0);
2bda0e17
KB
536}
537
538// Gets the column width
debe6624 539int wxListCtrl::GetColumnWidth(int col) const
2bda0e17 540{
edccf428 541 return ListView_GetColumnWidth(GetHwnd(), col);
2bda0e17
KB
542}
543
544// Sets the column width
debe6624 545bool wxListCtrl::SetColumnWidth(int col, int width)
2bda0e17 546{
0b5efdc7
VZ
547 int col2 = col;
548 if ( m_windowStyle & wxLC_LIST )
549 col2 = -1;
2bda0e17 550
0b5efdc7
VZ
551 int width2 = width;
552 if ( width2 == wxLIST_AUTOSIZE)
553 width2 = LVSCW_AUTOSIZE;
554 else if ( width2 == wxLIST_AUTOSIZE_USEHEADER)
555 width2 = LVSCW_AUTOSIZE_USEHEADER;
2bda0e17 556
edccf428 557 return (ListView_SetColumnWidth(GetHwnd(), col2, width2) != 0);
2bda0e17
KB
558}
559
560// Gets the number of items that can fit vertically in the
561// visible area of the list control (list or report view)
562// or the total number of items in the list control (icon
563// or small icon view)
c42404a5 564int wxListCtrl::GetCountPerPage() const
2bda0e17 565{
edccf428 566 return ListView_GetCountPerPage(GetHwnd());
2bda0e17
KB
567}
568
569// Gets the edit control for editing labels.
c42404a5 570wxTextCtrl* wxListCtrl::GetEditControl() const
2bda0e17 571{
bbcdf8bc 572 return m_textCtrl;
2bda0e17
KB
573}
574
575// Gets information about the item
576bool wxListCtrl::GetItem(wxListItem& info) const
577{
0b5efdc7 578 LV_ITEM lvItem;
11c7d5b6 579 wxZeroMemory(lvItem);
2bda0e17 580
0b5efdc7 581 lvItem.iItem = info.m_itemId;
fc5a93cd 582 lvItem.iSubItem = info.m_col;
0b5efdc7
VZ
583
584 if ( info.m_mask & wxLIST_MASK_TEXT )
585 {
586 lvItem.mask |= LVIF_TEXT;
837e5743 587 lvItem.pszText = new wxChar[513];
0b5efdc7
VZ
588 lvItem.cchTextMax = 512;
589 }
590 else
591 {
592 lvItem.pszText = NULL;
593 }
594
595 if (info.m_mask & wxLIST_MASK_DATA)
edccf428 596 lvItem.mask |= LVIF_PARAM;
0b5efdc7
VZ
597
598 if ( info.m_mask & wxLIST_MASK_STATE )
599 {
600 lvItem.mask |= LVIF_STATE;
601 // the other bits are hardly interesting anyhow
602 lvItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
603 }
604
605 bool success = ListView_GetItem((HWND)GetHWND(), &lvItem) != 0;
606 if ( !success )
607 {
608 wxLogError(_("Couldn't retrieve information about list control item %d."),
609 lvItem.iItem);
610 }
611 else
612 {
613 wxConvertFromMSWListItem(this, info, lvItem);
614 }
615
616 if (lvItem.pszText)
617 delete[] lvItem.pszText;
618
619 return success;
2bda0e17
KB
620}
621
622// Sets information about the item
623bool wxListCtrl::SetItem(wxListItem& info)
624{
0b5efdc7 625 LV_ITEM item;
2bda0e17 626 wxConvertToMSWListItem(this, info, item);
bdc72a22
VZ
627
628 // check whether it has any custom attributes
629 if ( info.HasAttributes() )
630 {
d62228a6 631 m_attrs.Put(item.iItem, (wxObject *)new wxListItemAttr(*info.GetAttributes()));
bdc72a22
VZ
632
633 m_hasAnyAttr = TRUE;
634 }
bdc72a22 635
0b5efdc7 636 item.cchTextMax = 0;
7cc98b3e
VZ
637 bool ok = ListView_SetItem(GetHwnd(), &item) != 0;
638 if ( ok && (info.m_mask & wxLIST_MASK_IMAGE) )
639 {
640 // make the change visible
641 ListView_Update(GetHwnd(), item.iItem);
642 }
643
644 return ok;
2bda0e17
KB
645}
646
debe6624 647long wxListCtrl::SetItem(long index, int col, const wxString& label, int imageId)
2bda0e17 648{
0b5efdc7
VZ
649 wxListItem info;
650 info.m_text = label;
651 info.m_mask = wxLIST_MASK_TEXT;
652 info.m_itemId = index;
653 info.m_col = col;
654 if ( imageId > -1 )
655 {
656 info.m_image = imageId;
657 info.m_mask |= wxLIST_MASK_IMAGE;
658 }
659 return SetItem(info);
2bda0e17
KB
660}
661
662
663// Gets the item state
debe6624 664int wxListCtrl::GetItemState(long item, long stateMask) const
2bda0e17 665{
0b5efdc7 666 wxListItem info;
2bda0e17 667
edccf428 668 info.m_mask = wxLIST_MASK_STATE;
0b5efdc7
VZ
669 info.m_stateMask = stateMask;
670 info.m_itemId = item;
2bda0e17 671
0b5efdc7
VZ
672 if (!GetItem(info))
673 return 0;
2bda0e17 674
0b5efdc7 675 return info.m_state;
2bda0e17
KB
676}
677
678// Sets the item state
debe6624 679bool wxListCtrl::SetItemState(long item, long state, long stateMask)
2bda0e17 680{
0b5efdc7 681 wxListItem info;
2bda0e17 682
edccf428 683 info.m_mask = wxLIST_MASK_STATE;
0b5efdc7
VZ
684 info.m_state = state;
685 info.m_stateMask = stateMask;
686 info.m_itemId = item;
2bda0e17 687
0b5efdc7 688 return SetItem(info);
2bda0e17
KB
689}
690
691// Sets the item image
debe6624 692bool wxListCtrl::SetItemImage(long item, int image, int selImage)
2bda0e17 693{
0b5efdc7 694 wxListItem info;
2bda0e17 695
edccf428 696 info.m_mask = wxLIST_MASK_IMAGE;
0b5efdc7
VZ
697 info.m_image = image;
698 info.m_itemId = item;
2bda0e17 699
0b5efdc7 700 return SetItem(info);
2bda0e17
KB
701}
702
703// Gets the item text
debe6624 704wxString wxListCtrl::GetItemText(long item) const
2bda0e17 705{
0b5efdc7 706 wxListItem info;
2bda0e17 707
edccf428 708 info.m_mask = wxLIST_MASK_TEXT;
0b5efdc7 709 info.m_itemId = item;
2bda0e17 710
0b5efdc7
VZ
711 if (!GetItem(info))
712 return wxString("");
713 return info.m_text;
2bda0e17
KB
714}
715
716// Sets the item text
debe6624 717void wxListCtrl::SetItemText(long item, const wxString& str)
2bda0e17 718{
0b5efdc7 719 wxListItem info;
2bda0e17 720
edccf428 721 info.m_mask = wxLIST_MASK_TEXT;
0b5efdc7
VZ
722 info.m_itemId = item;
723 info.m_text = str;
2bda0e17 724
0b5efdc7 725 SetItem(info);
2bda0e17
KB
726}
727
728// Gets the item data
debe6624 729long wxListCtrl::GetItemData(long item) const
2bda0e17 730{
0b5efdc7 731 wxListItem info;
2bda0e17 732
edccf428 733 info.m_mask = wxLIST_MASK_DATA;
0b5efdc7 734 info.m_itemId = item;
2bda0e17 735
0b5efdc7
VZ
736 if (!GetItem(info))
737 return 0;
738 return info.m_data;
2bda0e17
KB
739}
740
741// Sets the item data
debe6624 742bool wxListCtrl::SetItemData(long item, long data)
2bda0e17 743{
0b5efdc7 744 wxListItem info;
2bda0e17 745
edccf428 746 info.m_mask = wxLIST_MASK_DATA;
0b5efdc7
VZ
747 info.m_itemId = item;
748 info.m_data = data;
2bda0e17 749
0b5efdc7 750 return SetItem(info);
2bda0e17
KB
751}
752
753// Gets the item rectangle
16e93305 754bool wxListCtrl::GetItemRect(long item, wxRect& rect, int code) const
2bda0e17 755{
0b5efdc7 756 RECT rect2;
2bda0e17 757
0b5efdc7
VZ
758 int code2 = LVIR_BOUNDS;
759 if ( code == wxLIST_RECT_BOUNDS )
760 code2 = LVIR_BOUNDS;
761 else if ( code == wxLIST_RECT_ICON )
762 code2 = LVIR_ICON;
763 else if ( code == wxLIST_RECT_LABEL )
764 code2 = LVIR_LABEL;
2bda0e17 765
5ea105e0 766#ifdef __WXWINE__
edccf428 767 bool success = (ListView_GetItemRect(GetHwnd(), (int) item, &rect2 ) != 0);
5ea105e0 768#else
edccf428 769 bool success = (ListView_GetItemRect(GetHwnd(), (int) item, &rect2, code2) != 0);
5ea105e0 770#endif
2bda0e17 771
0b5efdc7
VZ
772 rect.x = rect2.left;
773 rect.y = rect2.top;
774 rect.width = rect2.right - rect2.left;
775 rect.height = rect2.bottom - rect2.left;
776 return success;
2bda0e17
KB
777}
778
779// Gets the item position
debe6624 780bool wxListCtrl::GetItemPosition(long item, wxPoint& pos) const
2bda0e17 781{
0b5efdc7 782 POINT pt;
2bda0e17 783
edccf428 784 bool success = (ListView_GetItemPosition(GetHwnd(), (int) item, &pt) != 0);
2bda0e17 785
0b5efdc7
VZ
786 pos.x = pt.x; pos.y = pt.y;
787 return success;
2bda0e17
KB
788}
789
790// Sets the item position.
debe6624 791bool wxListCtrl::SetItemPosition(long item, const wxPoint& pos)
2bda0e17 792{
edccf428 793 return (ListView_SetItemPosition(GetHwnd(), (int) item, pos.x, pos.y) != 0);
2bda0e17
KB
794}
795
796// Gets the number of items in the list control
c42404a5 797int wxListCtrl::GetItemCount() const
2bda0e17 798{
edccf428 799 return ListView_GetItemCount(GetHwnd());
2bda0e17
KB
800}
801
802// Retrieves the spacing between icons in pixels.
803// If small is TRUE, gets the spacing for the small icon
804// view, otherwise the large icon view.
805int wxListCtrl::GetItemSpacing(bool isSmall) const
806{
edccf428 807 return ListView_GetItemSpacing(GetHwnd(), (BOOL) isSmall);
2bda0e17
KB
808}
809
810// Gets the number of selected items in the list control
c42404a5 811int wxListCtrl::GetSelectedItemCount() const
2bda0e17 812{
edccf428 813 return ListView_GetSelectedCount(GetHwnd());
2bda0e17
KB
814}
815
816// Gets the text colour of the listview
c42404a5 817wxColour wxListCtrl::GetTextColour() const
2bda0e17 818{
edccf428 819 COLORREF ref = ListView_GetTextColor(GetHwnd());
0b5efdc7
VZ
820 wxColour col(GetRValue(ref), GetGValue(ref), GetBValue(ref));
821 return col;
2bda0e17
KB
822}
823
824// Sets the text colour of the listview
825void wxListCtrl::SetTextColour(const wxColour& col)
826{
910484a6 827 ListView_SetTextColor(GetHwnd(), PALETTERGB(col.Red(), col.Green(), col.Blue()));
2bda0e17
KB
828}
829
830// Gets the index of the topmost visible item when in
831// list or report view
c42404a5 832long wxListCtrl::GetTopItem() const
2bda0e17 833{
edccf428 834 return (long) ListView_GetTopIndex(GetHwnd());
2bda0e17
KB
835}
836
837// Searches for an item, starting from 'item'.
838// 'geometry' is one of
839// wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
840// 'state' is a state bit flag, one or more of
841// wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
842// item can be -1 to find the first item that matches the
843// specified flags.
844// Returns the item or -1 if unsuccessful.
debe6624 845long wxListCtrl::GetNextItem(long item, int geom, int state) const
2bda0e17 846{
0b5efdc7 847 long flags = 0;
2bda0e17 848
0b5efdc7
VZ
849 if ( geom == wxLIST_NEXT_ABOVE )
850 flags |= LVNI_ABOVE;
851 if ( geom == wxLIST_NEXT_ALL )
852 flags |= LVNI_ALL;
853 if ( geom == wxLIST_NEXT_BELOW )
854 flags |= LVNI_BELOW;
855 if ( geom == wxLIST_NEXT_LEFT )
856 flags |= LVNI_TOLEFT;
857 if ( geom == wxLIST_NEXT_RIGHT )
858 flags |= LVNI_TORIGHT;
2bda0e17 859
0b5efdc7
VZ
860 if ( state & wxLIST_STATE_CUT )
861 flags |= LVNI_CUT;
862 if ( state & wxLIST_STATE_DROPHILITED )
863 flags |= LVNI_DROPHILITED;
864 if ( state & wxLIST_STATE_FOCUSED )
865 flags |= LVNI_FOCUSED;
866 if ( state & wxLIST_STATE_SELECTED )
867 flags |= LVNI_SELECTED;
2bda0e17 868
edccf428 869 return (long) ListView_GetNextItem(GetHwnd(), item, flags);
2bda0e17
KB
870}
871
872
debe6624 873wxImageList *wxListCtrl::GetImageList(int which) const
2bda0e17 874{
0b5efdc7 875 if ( which == wxIMAGE_LIST_NORMAL )
2bda0e17 876 {
0b5efdc7
VZ
877 return m_imageListNormal;
878 }
879 else if ( which == wxIMAGE_LIST_SMALL )
2bda0e17 880 {
0b5efdc7
VZ
881 return m_imageListSmall;
882 }
883 else if ( which == wxIMAGE_LIST_STATE )
2bda0e17 884 {
0b5efdc7
VZ
885 return m_imageListState;
886 }
887 return NULL;
2bda0e17
KB
888}
889
debe6624 890void wxListCtrl::SetImageList(wxImageList *imageList, int which)
2bda0e17 891{
0b5efdc7
VZ
892 int flags = 0;
893 if ( which == wxIMAGE_LIST_NORMAL )
2bda0e17 894 {
0b5efdc7
VZ
895 flags = LVSIL_NORMAL;
896 m_imageListNormal = imageList;
897 }
898 else if ( which == wxIMAGE_LIST_SMALL )
2bda0e17 899 {
0b5efdc7
VZ
900 flags = LVSIL_SMALL;
901 m_imageListSmall = imageList;
902 }
903 else if ( which == wxIMAGE_LIST_STATE )
2bda0e17 904 {
0b5efdc7
VZ
905 flags = LVSIL_STATE;
906 m_imageListState = imageList;
907 }
edccf428 908 ListView_SetImageList(GetHwnd(), (HIMAGELIST) imageList ? imageList->GetHIMAGELIST() : 0, flags);
2bda0e17
KB
909}
910
edccf428 911// ----------------------------------------------------------------------------
2bda0e17 912// Operations
edccf428 913// ----------------------------------------------------------------------------
2bda0e17
KB
914
915// Arranges the items
debe6624 916bool wxListCtrl::Arrange(int flag)
2bda0e17 917{
0b5efdc7
VZ
918 UINT code = 0;
919 if ( flag == wxLIST_ALIGN_LEFT )
920 code = LVA_ALIGNLEFT;
921 else if ( flag == wxLIST_ALIGN_TOP )
922 code = LVA_ALIGNTOP;
923 else if ( flag == wxLIST_ALIGN_DEFAULT )
924 code = LVA_DEFAULT;
925 else if ( flag == wxLIST_ALIGN_SNAP_TO_GRID )
926 code = LVA_SNAPTOGRID;
2bda0e17 927
edccf428 928 return (ListView_Arrange(GetHwnd(), code) != 0);
2bda0e17
KB
929}
930
931// Deletes an item
debe6624 932bool wxListCtrl::DeleteItem(long item)
2bda0e17 933{
edccf428 934 return (ListView_DeleteItem(GetHwnd(), (int) item) != 0);
2bda0e17
KB
935}
936
937// Deletes all items
0b5efdc7 938bool wxListCtrl::DeleteAllItems()
2bda0e17 939{
edccf428 940 return (ListView_DeleteAllItems(GetHwnd()) != 0);
2bda0e17
KB
941}
942
943// Deletes all items
0b5efdc7 944bool wxListCtrl::DeleteAllColumns()
2bda0e17 945{
edccf428 946 while ( m_colCount > 0 )
2bda0e17 947 {
edccf428
VZ
948 if ( ListView_DeleteColumn(GetHwnd(), 0) == 0 )
949 {
950 wxLogLastError("ListView_DeleteColumn");
951
952 return FALSE;
953 }
954
955 m_colCount--;
2bda0e17 956 }
edccf428 957
223d09f6 958 wxASSERT_MSG( m_colCount == 0, wxT("no columns should be left") );
edccf428
VZ
959
960 return TRUE;
2bda0e17
KB
961}
962
963// Deletes a column
debe6624 964bool wxListCtrl::DeleteColumn(int col)
2bda0e17 965{
edccf428 966 bool success = (ListView_DeleteColumn(GetHwnd(), col) != 0);
2bda0e17
KB
967
968 if ( success && (m_colCount > 0) )
969 m_colCount --;
970 return success;
971}
972
973// Clears items, and columns if there are any.
0b5efdc7 974void wxListCtrl::ClearAll()
2bda0e17
KB
975{
976 DeleteAllItems();
977 if ( m_colCount > 0 )
978 DeleteAllColumns();
979}
980
bbcdf8bc
JS
981wxTextCtrl* wxListCtrl::EditLabel(long item, wxClassInfo* textControlClass)
982{
983 wxASSERT( (textControlClass->IsKindOf(CLASSINFO(wxTextCtrl))) );
984
edccf428 985 HWND hWnd = (HWND) ListView_EditLabel(GetHwnd(), item);
bbcdf8bc
JS
986
987 if (m_textCtrl)
988 {
0b5efdc7
VZ
989 m_textCtrl->UnsubclassWin();
990 m_textCtrl->SetHWND(0);
991 delete m_textCtrl;
992 m_textCtrl = NULL;
bbcdf8bc
JS
993 }
994
995 m_textCtrl = (wxTextCtrl*) textControlClass->CreateObject();
996 m_textCtrl->SetHWND((WXHWND) hWnd);
997 m_textCtrl->SubclassWin((WXHWND) hWnd);
998
999 return m_textCtrl;
1000}
1001
1002// End label editing, optionally cancelling the edit
1003bool wxListCtrl::EndEditLabel(bool cancel)
2bda0e17 1004{
341287bf 1005 wxFAIL;
bbcdf8bc 1006
0b5efdc7
VZ
1007 /* I don't know how to implement this: there's no such macro as ListView_EndEditLabelNow.
1008 * ???
edccf428 1009 bool success = (ListView_EndEditLabelNow(GetHwnd(), cancel) != 0);
0b5efdc7
VZ
1010
1011 if (m_textCtrl)
1012 {
1013 m_textCtrl->UnsubclassWin();
1014 m_textCtrl->SetHWND(0);
1015 delete m_textCtrl;
1016 m_textCtrl = NULL;
1017 }
1018 return success;
1019 */
1020 return FALSE;
2bda0e17
KB
1021}
1022
bbcdf8bc 1023
2bda0e17 1024// Ensures this item is visible
debe6624 1025bool wxListCtrl::EnsureVisible(long item)
2bda0e17 1026{
edccf428 1027 return (ListView_EnsureVisible(GetHwnd(), (int) item, FALSE) != 0);
2bda0e17
KB
1028}
1029
1030// Find an item whose label matches this string, starting from the item after 'start'
1031// or the beginning if 'start' is -1.
debe6624 1032long wxListCtrl::FindItem(long start, const wxString& str, bool partial)
2bda0e17 1033{
0b5efdc7 1034 LV_FINDINFO findInfo;
2bda0e17 1035
0b5efdc7
VZ
1036 findInfo.flags = LVFI_STRING;
1037 if ( partial )
1038 findInfo.flags |= LVFI_STRING;
1039 findInfo.psz = WXSTRINGCAST str;
2bda0e17 1040
edccf428 1041 return ListView_FindItem(GetHwnd(), (int) start, & findInfo);
2bda0e17
KB
1042}
1043
1044// Find an item whose data matches this data, starting from the item after 'start'
1045// or the beginning if 'start' is -1.
debe6624 1046long wxListCtrl::FindItem(long start, long data)
2bda0e17 1047{
0b5efdc7 1048 LV_FINDINFO findInfo;
2bda0e17 1049
0b5efdc7
VZ
1050 findInfo.flags = LVFI_PARAM;
1051 findInfo.lParam = data;
2bda0e17 1052
edccf428 1053 return ListView_FindItem(GetHwnd(), (int) start, & findInfo);
2bda0e17
KB
1054}
1055
1056// Find an item nearest this position in the specified direction, starting from
1057// the item after 'start' or the beginning if 'start' is -1.
debe6624 1058long wxListCtrl::FindItem(long start, const wxPoint& pt, int direction)
2bda0e17 1059{
0b5efdc7 1060 LV_FINDINFO findInfo;
2bda0e17 1061
0b5efdc7
VZ
1062 findInfo.flags = LVFI_NEARESTXY;
1063 findInfo.pt.x = pt.x;
1064 findInfo.pt.y = pt.y;
acb62b84 1065 findInfo.vkDirection = VK_RIGHT;
2bda0e17 1066
0b5efdc7
VZ
1067 if ( direction == wxLIST_FIND_UP )
1068 findInfo.vkDirection = VK_UP;
1069 else if ( direction == wxLIST_FIND_DOWN )
1070 findInfo.vkDirection = VK_DOWN;
1071 else if ( direction == wxLIST_FIND_LEFT )
1072 findInfo.vkDirection = VK_LEFT;
1073 else if ( direction == wxLIST_FIND_RIGHT )
1074 findInfo.vkDirection = VK_RIGHT;
1075
edccf428 1076 return ListView_FindItem(GetHwnd(), (int) start, & findInfo);
2bda0e17
KB
1077}
1078
1079// Determines which item (if any) is at the specified point,
1080// giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1081long wxListCtrl::HitTest(const wxPoint& point, int& flags)
1082{
1083 LV_HITTESTINFO hitTestInfo;
0b5efdc7
VZ
1084 hitTestInfo.pt.x = (int) point.x;
1085 hitTestInfo.pt.y = (int) point.y;
2bda0e17 1086
edccf428 1087 ListView_HitTest(GetHwnd(), & hitTestInfo);
2bda0e17 1088
0b5efdc7
VZ
1089 flags = 0;
1090 if ( hitTestInfo.flags & LVHT_ABOVE )
1091 flags |= wxLIST_HITTEST_ABOVE;
1092 if ( hitTestInfo.flags & LVHT_BELOW )
1093 flags |= wxLIST_HITTEST_BELOW;
1094 if ( hitTestInfo.flags & LVHT_NOWHERE )
1095 flags |= wxLIST_HITTEST_NOWHERE;
1096 if ( hitTestInfo.flags & LVHT_ONITEMICON )
1097 flags |= wxLIST_HITTEST_ONITEMICON;
1098 if ( hitTestInfo.flags & LVHT_ONITEMLABEL )
1099 flags |= wxLIST_HITTEST_ONITEMLABEL;
1100 if ( hitTestInfo.flags & LVHT_ONITEMSTATEICON )
1101 flags |= wxLIST_HITTEST_ONITEMSTATEICON;
1102 if ( hitTestInfo.flags & LVHT_TOLEFT )
1103 flags |= wxLIST_HITTEST_TOLEFT;
1104 if ( hitTestInfo.flags & LVHT_TORIGHT )
1105 flags |= wxLIST_HITTEST_TORIGHT;
1106
edccf428 1107 return (long) hitTestInfo.iItem;
2bda0e17
KB
1108}
1109
1110// Inserts an item, returning the index of the new item if successful,
1111// -1 otherwise.
2bda0e17
KB
1112long wxListCtrl::InsertItem(wxListItem& info)
1113{
0b5efdc7
VZ
1114 LV_ITEM item;
1115 wxConvertToMSWListItem(this, info, item);
2bda0e17 1116
bdc72a22
VZ
1117 // check whether it has any custom attributes
1118 if ( info.HasAttributes() )
1119 {
d62228a6 1120 m_attrs.Put(item.iItem, (wxObject *)new wxListItemAttr(*info.GetAttributes()));
bdc72a22
VZ
1121
1122 m_hasAnyAttr = TRUE;
1123 }
bdc72a22 1124
edccf428 1125 return (long) ListView_InsertItem(GetHwnd(), & item);
2bda0e17
KB
1126}
1127
debe6624 1128long wxListCtrl::InsertItem(long index, const wxString& label)
2bda0e17 1129{
0b5efdc7
VZ
1130 wxListItem info;
1131 info.m_text = label;
1132 info.m_mask = wxLIST_MASK_TEXT;
1133 info.m_itemId = index;
1134 return InsertItem(info);
2bda0e17
KB
1135}
1136
1137// Inserts an image item
debe6624 1138long wxListCtrl::InsertItem(long index, int imageIndex)
2bda0e17 1139{
0b5efdc7
VZ
1140 wxListItem info;
1141 info.m_image = imageIndex;
1142 info.m_mask = wxLIST_MASK_IMAGE;
1143 info.m_itemId = index;
1144 return InsertItem(info);
2bda0e17
KB
1145}
1146
1147// Inserts an image/string item
debe6624 1148long wxListCtrl::InsertItem(long index, const wxString& label, int imageIndex)
2bda0e17 1149{
0b5efdc7
VZ
1150 wxListItem info;
1151 info.m_image = imageIndex;
1152 info.m_text = label;
1153 info.m_mask = wxLIST_MASK_IMAGE | wxLIST_MASK_TEXT;
1154 info.m_itemId = index;
1155 return InsertItem(info);
2bda0e17
KB
1156}
1157
1158// For list view mode (only), inserts a column.
debe6624 1159long wxListCtrl::InsertColumn(long col, wxListItem& item)
2bda0e17 1160{
0b5efdc7
VZ
1161 LV_COLUMN lvCol;
1162 lvCol.mask = 0;
1163 lvCol.fmt = 0;
1164 lvCol.pszText = NULL;
1165
1166 if ( item.m_mask & wxLIST_MASK_TEXT )
1167 {
1168 lvCol.mask |= LVCF_TEXT;
1169 lvCol.pszText = WXSTRINGCAST item.m_text;
1170 lvCol.cchTextMax = 0; // Ignored
1171 }
1172 if ( item.m_mask & wxLIST_MASK_FORMAT )
1173 {
1174 lvCol.mask |= LVCF_FMT;
1175
1176 if ( item.m_format == wxLIST_FORMAT_LEFT )
1177 lvCol.fmt = LVCFMT_LEFT;
1178 if ( item.m_format == wxLIST_FORMAT_RIGHT )
1179 lvCol.fmt = LVCFMT_RIGHT;
1180 if ( item.m_format == wxLIST_FORMAT_CENTRE )
1181 lvCol.fmt = LVCFMT_CENTER;
2bda0e17
KB
1182 }
1183
e373f51b 1184 lvCol.mask |= LVCF_WIDTH;
0b5efdc7
VZ
1185 if ( item.m_mask & wxLIST_MASK_WIDTH )
1186 {
e373f51b 1187 if ( item.m_width == wxLIST_AUTOSIZE)
0b5efdc7 1188 lvCol.cx = LVSCW_AUTOSIZE;
e373f51b 1189 else if ( item.m_width == wxLIST_AUTOSIZE_USEHEADER)
0b5efdc7 1190 lvCol.cx = LVSCW_AUTOSIZE_USEHEADER;
e373f51b
VZ
1191 else
1192 lvCol.cx = item.m_width;
1193 }
1194 else
1195 {
1196 // always give some width to the new column: this one is compatible
1197 // with wxGTK
1198 lvCol.cx = 80;
0b5efdc7 1199 }
e373f51b 1200
0b5efdc7
VZ
1201 lvCol.mask |= LVCF_SUBITEM;
1202 lvCol.iSubItem = col;
2bda0e17 1203
edccf428 1204 bool success = ListView_InsertColumn(GetHwnd(), col, & lvCol) != -1;
2bda0e17 1205 if ( success )
e373f51b
VZ
1206 {
1207 m_colCount++;
1208 }
1209 else
1210 {
223d09f6 1211 wxLogDebug(wxT("Failed to insert the column '%s' into listview!"),
e373f51b
VZ
1212 lvCol.pszText);
1213 }
1214
2bda0e17
KB
1215 return success;
1216}
1217
bdc72a22
VZ
1218long wxListCtrl::InsertColumn(long col,
1219 const wxString& heading,
1220 int format,
1221 int width)
2bda0e17 1222{
0b5efdc7
VZ
1223 wxListItem item;
1224 item.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_FORMAT;
1225 item.m_text = heading;
1226 if ( width > -1 )
1227 {
1228 item.m_mask |= wxLIST_MASK_WIDTH;
1229 item.m_width = width;
1230 }
1231 item.m_format = format;
2bda0e17 1232
0b5efdc7 1233 return InsertColumn(col, item);
2bda0e17
KB
1234}
1235
1236// Scrolls the list control. If in icon, small icon or report view mode,
1237// x specifies the number of pixels to scroll. If in list view mode, x
1238// specifies the number of columns to scroll.
1239// If in icon, small icon or list view mode, y specifies the number of pixels
1240// to scroll. If in report view mode, y specifies the number of lines to scroll.
debe6624 1241bool wxListCtrl::ScrollList(int dx, int dy)
2bda0e17 1242{
edccf428 1243 return (ListView_Scroll(GetHwnd(), dx, dy) != 0);
2bda0e17
KB
1244}
1245
1246// Sort items.
1247
1248// fn is a function which takes 3 long arguments: item1, item2, data.
1249// item1 is the long data associated with a first item (NOT the index).
1250// item2 is the long data associated with a second item (NOT the index).
1251// data is the same value as passed to SortItems.
1252// The return value is a negative number if the first item should precede the second
1253// item, a positive number of the second item should precede the first,
1254// or zero if the two items are equivalent.
1255
1256// data is arbitrary data to be passed to the sort function.
1257bool wxListCtrl::SortItems(wxListCtrlCompare fn, long data)
1258{
edccf428 1259 return (ListView_SortItems(GetHwnd(), (PFNLVCOMPARE) fn, data) != 0);
2bda0e17
KB
1260}
1261
edccf428
VZ
1262// ----------------------------------------------------------------------------
1263// message processing
1264// ----------------------------------------------------------------------------
1265
debe6624 1266bool wxListCtrl::MSWCommand(WXUINT cmd, WXWORD id)
2bda0e17 1267{
0b5efdc7 1268 if (cmd == EN_UPDATE)
acb62b84 1269 {
0b5efdc7
VZ
1270 wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, id);
1271 event.SetEventObject( this );
1272 ProcessCommand(event);
1273 return TRUE;
acb62b84 1274 }
0b5efdc7 1275 else if (cmd == EN_KILLFOCUS)
acb62b84 1276 {
0b5efdc7
VZ
1277 wxCommandEvent event(wxEVT_KILL_FOCUS, id);
1278 event.SetEventObject( this );
1279 ProcessCommand(event);
1280 return TRUE;
acb62b84 1281 }
edccf428
VZ
1282 else
1283 return FALSE;
0b5efdc7
VZ
1284}
1285
a23fd0e1 1286bool wxListCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
0b5efdc7 1287{
bdc72a22
VZ
1288 // prepare the event
1289 // -----------------
1290
0b5efdc7
VZ
1291 wxListEvent event(wxEVT_NULL, m_windowId);
1292 wxEventType eventType = wxEVT_NULL;
225fe9d6 1293
bdc72a22 1294 NMHDR *nmhdr = (NMHDR *)lParam;
225fe9d6
VZ
1295
1296 // almost all messages use NM_LISTVIEW
1297 NM_LISTVIEW *nmLV = (NM_LISTVIEW *)nmhdr;
1298
1299 // this is true for almost all events
1300 event.m_item.m_data = nmLV->lParam;
1301
bdc72a22 1302 switch ( nmhdr->code )
acb62b84 1303 {
0b5efdc7 1304 case LVN_BEGINRDRAG:
bdc72a22 1305 eventType = wxEVT_COMMAND_LIST_BEGIN_RDRAG;
0b5efdc7 1306 // fall through
cb0f56f9 1307
0b5efdc7
VZ
1308 case LVN_BEGINDRAG:
1309 if ( eventType == wxEVT_NULL )
1310 {
1311 eventType = wxEVT_COMMAND_LIST_BEGIN_DRAG;
1312 }
1313
225fe9d6
VZ
1314 event.m_itemIndex = nmLV->iItem;
1315 event.m_pointDrag.x = nmLV->ptAction.x;
1316 event.m_pointDrag.y = nmLV->ptAction.y;
0b5efdc7
VZ
1317 break;
1318
1319 case LVN_BEGINLABELEDIT:
1320 {
1321 eventType = wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT;
1322 LV_DISPINFO *info = (LV_DISPINFO *)lParam;
edccf428 1323 wxConvertFromMSWListItem(this, event.m_item, info->item, GetHwnd());
0b5efdc7 1324 }
225fe9d6 1325 break;
0b5efdc7
VZ
1326
1327 case LVN_COLUMNCLICK:
225fe9d6
VZ
1328 eventType = wxEVT_COMMAND_LIST_COL_CLICK;
1329 event.m_itemIndex = -1;
1330 event.m_col = nmLV->iSubItem;
1331 break;
5ea47806 1332
0b5efdc7 1333 case LVN_DELETEALLITEMS:
6932a32c 1334 eventType = wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS;
5ea47806 1335 event.m_itemIndex = -1;
5ea47806 1336
6932a32c 1337 FreeAllAttrs();
bdc72a22 1338
6932a32c 1339 break;
5ea47806 1340
0b5efdc7 1341 case LVN_DELETEITEM:
225fe9d6
VZ
1342 eventType = wxEVT_COMMAND_LIST_DELETE_ITEM;
1343 event.m_itemIndex = nmLV->iItem;
bdc72a22 1344
225fe9d6
VZ
1345 if ( m_hasAnyAttr )
1346 {
1347 delete (wxListItemAttr *)m_attrs.Delete(nmLV->iItem);
0b5efdc7 1348 }
bdc72a22
VZ
1349 break;
1350
0b5efdc7
VZ
1351 case LVN_ENDLABELEDIT:
1352 {
1353 eventType = wxEVT_COMMAND_LIST_END_LABEL_EDIT;
1354 LV_DISPINFO *info = (LV_DISPINFO *)lParam;
1ee4ead5 1355 wxConvertFromMSWListItem(this, event.m_item, info->item);
0b5efdc7 1356 if ( info->item.pszText == NULL || info->item.iItem == -1 )
1ee4ead5 1357 return FALSE;
0b5efdc7 1358 }
bdc72a22
VZ
1359 break;
1360
1361 case LVN_SETDISPINFO:
1362 {
1363 eventType = wxEVT_COMMAND_LIST_SET_INFO;
1364 LV_DISPINFO *info = (LV_DISPINFO *)lParam;
1365 wxConvertFromMSWListItem(this, event.m_item, info->item, GetHwnd());
1366 }
1367 break;
edccf428 1368
bdc72a22 1369 case LVN_GETDISPINFO:
edccf428
VZ
1370 // this provokes stack overflow: indeed, wxConvertFromMSWListItem()
1371 // sends us WM_NOTIFY! As it doesn't do anything for now, just leave
1372 // it out.
1373#if 0
0b5efdc7 1374 {
0b5efdc7
VZ
1375 // TODO: some text buffering here, I think
1376 // TODO: API for getting Windows to retrieve values
1377 // on demand.
1378 eventType = wxEVT_COMMAND_LIST_GET_INFO;
1379 LV_DISPINFO *info = (LV_DISPINFO *)lParam;
edccf428 1380 wxConvertFromMSWListItem(this, event.m_item, info->item, GetHwnd());
0b5efdc7
VZ
1381 break;
1382 }
edccf428 1383#endif // 0
bdc72a22
VZ
1384 return FALSE;
1385
edccf428 1386
0b5efdc7 1387 case LVN_INSERTITEM:
225fe9d6
VZ
1388 eventType = wxEVT_COMMAND_LIST_INSERT_ITEM;
1389 event.m_itemIndex = nmLV->iItem;
1390 break;
bdc72a22 1391
0b5efdc7 1392 case LVN_ITEMCHANGED:
225fe9d6
VZ
1393 // This needs to be sent to wxListCtrl as a rather more concrete
1394 // event. For now, just detect a selection or deselection.
1395 if ( (nmLV->uNewState & LVIS_SELECTED) && !(nmLV->uOldState & LVIS_SELECTED) )
0b5efdc7 1396 {
225fe9d6
VZ
1397 eventType = wxEVT_COMMAND_LIST_ITEM_SELECTED;
1398 event.m_itemIndex = nmLV->iItem;
1399 }
1400 else if ( !(nmLV->uNewState & LVIS_SELECTED) && (nmLV->uOldState & LVIS_SELECTED) )
1401 {
1402 eventType = wxEVT_COMMAND_LIST_ITEM_DESELECTED;
1403 event.m_itemIndex = nmLV->iItem;
0b5efdc7 1404 }
225fe9d6
VZ
1405 else
1406 {
1407 return FALSE;
1408 }
1409 break;
edccf428 1410
0b5efdc7
VZ
1411 case LVN_KEYDOWN:
1412 {
0b5efdc7 1413 LV_KEYDOWN *info = (LV_KEYDOWN *)lParam;
edccf428
VZ
1414 WORD wVKey = info->wVKey;
1415
1416 // get the current selection
1417 long lItem = GetNextItem(-1,
1418 wxLIST_NEXT_ALL,
1419 wxLIST_STATE_SELECTED);
1420
1421 // <Enter> or <Space> activate the selected item if any
1422 if ( lItem != -1 && (wVKey == VK_RETURN || wVKey == VK_SPACE) )
1423 {
1424 // TODO this behaviour probably should be optional
1425 eventType = wxEVT_COMMAND_LIST_ITEM_ACTIVATED;
1426 event.m_itemIndex = lItem;
1427 }
1428 else
1429 {
1430 eventType = wxEVT_COMMAND_LIST_KEY_DOWN;
1431 event.m_code = wxCharCodeMSWToWX(wVKey);
1432 }
225fe9d6
VZ
1433
1434 event.m_item.m_data = GetItemData(lItem);
0b5efdc7 1435 }
225fe9d6 1436 break;
edccf428
VZ
1437
1438 case NM_DBLCLK:
1439 // if the user processes it in wxEVT_COMMAND_LEFT_CLICK(), don't do
1440 // anything else
1441 if ( wxControl::MSWOnNotify(idCtrl, lParam, result) )
1442 {
1443 return TRUE;
1444 }
1445
1446 // else translate it into wxEVT_COMMAND_LIST_ITEM_ACTIVATED event
5bd3a2da 1447 // if it happened on an item (and not on empty place)
225fe9d6 1448 if ( nmLV->iItem == -1 )
1ee4ead5 1449 {
225fe9d6
VZ
1450 // not on item
1451 return FALSE;
1ee4ead5 1452 }
225fe9d6
VZ
1453
1454 eventType = wxEVT_COMMAND_LIST_ITEM_ACTIVATED;
1455 event.m_itemIndex = nmLV->iItem;
1456 event.m_item.m_data = GetItemData(nmLV->iItem);
edccf428 1457 break;
cb0f56f9
VZ
1458
1459 case NM_RCLICK:
225fe9d6
VZ
1460 /* TECH NOTE: NM_RCLICK isn't really good enough here. We want to
1461 subclass and check for the actual WM_RBUTTONDOWN message,
1462 because NM_RCLICK waits for the WM_RBUTTONUP message as well
1463 before firing off. We want to have notify events for both down
1464 -and- up. */
1465 {
1466 // if the user processes it in wxEVT_COMMAND_RIGHT_CLICK(),
1467 // don't do anything else
1468 if ( wxControl::MSWOnNotify(idCtrl, lParam, result) )
1469 {
1470 return TRUE;
1471 }
cb0f56f9 1472
225fe9d6
VZ
1473 // else translate it into wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK event
1474 LV_HITTESTINFO lvhti;
1475 wxZeroMemory(lvhti);
11c7d5b6 1476
225fe9d6
VZ
1477 ::GetCursorPos(&(lvhti.pt));
1478 ::ScreenToClient(GetHwnd(),&(lvhti.pt));
1479 if ( ListView_HitTest(GetHwnd(),&lvhti) != -1 )
cb0f56f9 1480 {
225fe9d6
VZ
1481 if ( lvhti.flags & LVHT_ONITEM )
1482 {
1483 eventType = wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK;
1484 event.m_itemIndex = lvhti.iItem;
1485 }
cb0f56f9 1486 }
9bfa7bfc 1487 }
cb0f56f9
VZ
1488 break;
1489
bdc72a22
VZ
1490#if 0
1491 case NM_MCLICK: // ***** THERE IS NO NM_MCLICK. Subclass anyone? ******
1492 {
1493 // if the user processes it in wxEVT_COMMAND_MIDDLE_CLICK(), don't do
1494 // anything else
1495 if ( wxControl::MSWOnNotify(idCtrl, lParam, result) )
1496 {
1497 return TRUE;
1498 }
cb0f56f9 1499
bdc72a22
VZ
1500 // else translate it into wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK event
1501 eventType = wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK;
1502 NMITEMACTIVATE* hdr = (NMITEMACTIVATE*)lParam;
1503 event.m_itemIndex = hdr->iItem;
1504 }
1505 break;
1506#endif // 0
1507
6ecfe2ac 1508#if defined(_WIN32_IE) && _WIN32_IE >= 0x300
bdc72a22 1509 case NM_CUSTOMDRAW:
0b5efdc7 1510 {
bdc72a22
VZ
1511 LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)lParam;
1512 NMCUSTOMDRAW& nmcd = lplvcd->nmcd;
1513 switch( nmcd.dwDrawStage )
1514 {
d62228a6 1515 case CDDS_PREPAINT:
bdc72a22
VZ
1516 // if we've got any items with non standard attributes,
1517 // notify us before painting each item
1518 *result = m_hasAnyAttr ? CDRF_NOTIFYITEMDRAW
1519 : CDRF_DODEFAULT;
1520 return TRUE;
1521
1522 case CDDS_ITEMPREPAINT:
1523 {
d62228a6
VZ
1524 wxListItemAttr *attr =
1525 (wxListItemAttr *)m_attrs.Get(nmcd.dwItemSpec);
1526
1527 if ( !attr )
bdc72a22
VZ
1528 {
1529 // nothing to do for this item
1530 return CDRF_DODEFAULT;
1531 }
1532
d62228a6
VZ
1533 HFONT hFont;
1534 wxColour colText, colBack;
1535 if ( attr->HasFont() )
1536 {
1537 wxFont font = attr->GetFont();
1538 hFont = (HFONT)font.GetResourceHandle();
1539 }
1540 else
1541 {
1542 hFont = 0;
1543 }
1544
1545 if ( attr->HasTextColour() )
1546 {
1547 colText = attr->GetTextColour();
1548 }
1549 else
1550 {
1551 colText = GetTextColour();
1552 }
1553
1554 if ( attr->HasBackgroundColour() )
1555 {
1556 colBack = attr->GetBackgroundColour();
1557 }
1558 else
1559 {
1560 colBack = GetBackgroundColour();
1561 }
1562
1563 // note that if we wanted to set colours for
1564 // individual columns (subitems), we would have
1565 // returned CDRF_NOTIFYSUBITEMREDRAW from here
1566 if ( hFont )
1567 {
1568 ::SelectObject(nmcd.hdc, hFont);
bdc72a22 1569
d62228a6
VZ
1570 *result = CDRF_NEWFONT;
1571 }
1572 else
1573 {
1574 *result = CDRF_DODEFAULT;
1575 }
bdc72a22 1576
d62228a6
VZ
1577 lplvcd->clrText = wxColourToRGB(colText);
1578 lplvcd->clrTextBk = wxColourToRGB(colBack);
bdc72a22
VZ
1579
1580 return TRUE;
1581 }
d62228a6
VZ
1582
1583 default:
1584 *result = CDRF_DODEFAULT;
1585 return TRUE;
bdc72a22 1586 }
0b5efdc7 1587 }
bdc72a22 1588 break;
6ecfe2ac 1589#endif // _WIN32_IE >= 0x300
0b5efdc7 1590
edccf428 1591 default:
a23fd0e1 1592 return wxControl::MSWOnNotify(idCtrl, lParam, result);
acb62b84
VZ
1593 }
1594
bdc72a22
VZ
1595 // process the event
1596 // -----------------
1597
0b5efdc7
VZ
1598 event.SetEventObject( this );
1599 event.SetEventType(eventType);
acb62b84 1600
0b5efdc7
VZ
1601 if ( !GetEventHandler()->ProcessEvent(event) )
1602 return FALSE;
acb62b84 1603
bdc72a22
VZ
1604 // post processing
1605 // ---------------
1606
225fe9d6 1607 switch ( nmhdr->code )
acb62b84 1608 {
6932a32c
VZ
1609 case LVN_DELETEALLITEMS:
1610 // always return TRUE to suppress all additional LVN_DELETEITEM
1611 // notifications - this makes deleting all items from a list ctrl
1612 // much faster
1613 *result = TRUE;
1614
1615 return TRUE;
1616
1ee4ead5 1617 case LVN_GETDISPINFO:
0b5efdc7 1618 {
1ee4ead5
VZ
1619 LV_DISPINFO *info = (LV_DISPINFO *)lParam;
1620 if ( info->item.mask & LVIF_TEXT )
1621 {
1622 if ( !event.m_item.m_text.IsNull() )
1623 {
1624 info->item.pszText = AddPool(event.m_item.m_text);
1625 info->item.cchTextMax = wxStrlen(info->item.pszText) + 1;
1626 }
1627 }
1628 // wxConvertToMSWListItem(this, event.m_item, info->item);
1629 break;
0b5efdc7 1630 }
1ee4ead5
VZ
1631 case LVN_ENDLABELEDIT:
1632 {
1633 *result = event.IsAllowed();
1634 return TRUE;
1635 }
acb62b84 1636 }
acb62b84 1637
0b5efdc7 1638 *result = !event.IsAllowed();
fd3f686c 1639
0b5efdc7 1640 return TRUE;
2bda0e17
KB
1641}
1642
837e5743 1643wxChar *wxListCtrl::AddPool(const wxString& str)
2bda0e17 1644{
0b5efdc7
VZ
1645 // Remove the first element if 3 strings exist
1646 if ( m_stringPool.Number() == 3 )
1647 {
1648 wxNode *node = m_stringPool.First();
1649 delete[] (char *)node->Data();
1650 delete node;
1651 }
837e5743
OK
1652 wxNode *node = m_stringPool.Add(WXSTRINGCAST str);
1653 return (wxChar *)node->Data();
2bda0e17
KB
1654}
1655
edccf428
VZ
1656// ----------------------------------------------------------------------------
1657// wxListItem
1658// ----------------------------------------------------------------------------
1659
2bda0e17 1660// List item structure
0b5efdc7 1661wxListItem::wxListItem()
2bda0e17
KB
1662{
1663 m_mask = 0;
1664 m_itemId = 0;
1665 m_col = 0;
1666 m_state = 0;
1667 m_stateMask = 0;
1668 m_image = 0;
0b5efdc7 1669 m_data = 0;
2bda0e17 1670
0b5efdc7
VZ
1671 m_format = wxLIST_FORMAT_CENTRE;
1672 m_width = 0;
bdc72a22
VZ
1673
1674 m_attr = NULL;
2bda0e17
KB
1675}
1676
9b00bb16
RR
1677void wxListItem::Clear()
1678{
1679 m_mask = 0;
1680 m_itemId = 0;
1681 m_col = 0;
1682 m_state = 0;
1683 m_stateMask = 0;
1684 m_image = 0;
1685 m_data = 0;
1686 m_format = wxLIST_FORMAT_CENTRE;
1687 m_width = 0;
1688 m_text = wxEmptyString;
1689
1690 if (m_attr) delete m_attr;
1691 m_attr = NULL;
1692}
1693
1694void wxListItem::ClearAttributes()
1695{
1696 if (m_attr) delete m_attr;
1697 m_attr = NULL;
1698}
1699
2bda0e17
KB
1700static void wxConvertFromMSWListItem(const wxListCtrl *ctrl, wxListItem& info, LV_ITEM& lvItem, HWND getFullInfo)
1701{
0b5efdc7
VZ
1702 info.m_data = lvItem.lParam;
1703 info.m_mask = 0;
1704 info.m_state = 0;
1705 info.m_stateMask = 0;
1706 info.m_itemId = lvItem.iItem;
acb62b84 1707
0b5efdc7 1708 long oldMask = lvItem.mask;
acb62b84 1709
0b5efdc7
VZ
1710 bool needText = FALSE;
1711 if (getFullInfo != 0)
acb62b84 1712 {
0b5efdc7
VZ
1713 if ( lvItem.mask & LVIF_TEXT )
1714 needText = FALSE;
1715 else
1716 needText = TRUE;
acb62b84 1717
0b5efdc7
VZ
1718 if ( needText )
1719 {
837e5743 1720 lvItem.pszText = new wxChar[513];
0b5efdc7
VZ
1721 lvItem.cchTextMax = 512;
1722 }
edccf428
VZ
1723 // lvItem.mask |= TVIF_HANDLE | TVIF_STATE | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_CHILDREN | TVIF_PARAM;
1724 lvItem.mask |= LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
1725 ::SendMessage(getFullInfo, LVM_GETITEM, 0, (LPARAM)& lvItem);
0b5efdc7 1726 }
acb62b84 1727
0b5efdc7 1728 if ( lvItem.mask & LVIF_STATE )
acb62b84 1729 {
0b5efdc7
VZ
1730 info.m_mask |= wxLIST_MASK_STATE;
1731
1732 if ( lvItem.stateMask & LVIS_CUT)
1733 {
edccf428 1734 info.m_stateMask |= wxLIST_STATE_CUT;
0b5efdc7 1735 if ( lvItem.state & LVIS_CUT )
edccf428 1736 info.m_state |= wxLIST_STATE_CUT;
0b5efdc7
VZ
1737 }
1738 if ( lvItem.stateMask & LVIS_DROPHILITED)
1739 {
edccf428 1740 info.m_stateMask |= wxLIST_STATE_DROPHILITED;
0b5efdc7 1741 if ( lvItem.state & LVIS_DROPHILITED )
edccf428 1742 info.m_state |= wxLIST_STATE_DROPHILITED;
0b5efdc7
VZ
1743 }
1744 if ( lvItem.stateMask & LVIS_FOCUSED)
1745 {
edccf428 1746 info.m_stateMask |= wxLIST_STATE_FOCUSED;
0b5efdc7 1747 if ( lvItem.state & LVIS_FOCUSED )
edccf428 1748 info.m_state |= wxLIST_STATE_FOCUSED;
0b5efdc7
VZ
1749 }
1750 if ( lvItem.stateMask & LVIS_SELECTED)
1751 {
edccf428 1752 info.m_stateMask |= wxLIST_STATE_SELECTED;
0b5efdc7 1753 if ( lvItem.state & LVIS_SELECTED )
edccf428 1754 info.m_state |= wxLIST_STATE_SELECTED;
0b5efdc7 1755 }
acb62b84 1756 }
0b5efdc7
VZ
1757
1758 if ( lvItem.mask & LVIF_TEXT )
acb62b84 1759 {
0b5efdc7
VZ
1760 info.m_mask |= wxLIST_MASK_TEXT;
1761 info.m_text = lvItem.pszText;
acb62b84 1762 }
0b5efdc7 1763 if ( lvItem.mask & LVIF_IMAGE )
acb62b84 1764 {
0b5efdc7
VZ
1765 info.m_mask |= wxLIST_MASK_IMAGE;
1766 info.m_image = lvItem.iImage;
acb62b84 1767 }
0b5efdc7
VZ
1768 if ( lvItem.mask & LVIF_PARAM )
1769 info.m_mask |= wxLIST_MASK_DATA;
1770 if ( lvItem.mask & LVIF_DI_SETITEM )
1771 info.m_mask |= wxLIST_SET_ITEM;
1772 info.m_col = lvItem.iSubItem;
1773
1774 if (needText)
acb62b84 1775 {
0b5efdc7
VZ
1776 if (lvItem.pszText)
1777 delete[] lvItem.pszText;
acb62b84 1778 }
edccf428 1779 lvItem.mask = oldMask;
2bda0e17
KB
1780}
1781
1782static void wxConvertToMSWListItem(const wxListCtrl *ctrl, wxListItem& info, LV_ITEM& lvItem)
1783{
edccf428 1784 lvItem.iItem = (int) info.m_itemId;
acb62b84 1785
edccf428 1786 lvItem.iImage = info.m_image;
0b5efdc7
VZ
1787 lvItem.lParam = info.m_data;
1788 lvItem.stateMask = 0;
1789 lvItem.state = 0;
1790 lvItem.mask = 0;
1791 lvItem.iSubItem = info.m_col;
acb62b84 1792
0b5efdc7 1793 if (info.m_mask & wxLIST_MASK_STATE)
acb62b84 1794 {
edccf428 1795 lvItem.mask |= LVIF_STATE;
0b5efdc7
VZ
1796 if (info.m_stateMask & wxLIST_STATE_CUT)
1797 {
edccf428 1798 lvItem.stateMask |= LVIS_CUT;
0b5efdc7
VZ
1799 if (info.m_state & wxLIST_STATE_CUT)
1800 lvItem.state |= LVIS_CUT;
1801 }
1802 if (info.m_stateMask & wxLIST_STATE_DROPHILITED)
1803 {
1804 lvItem.stateMask |= LVIS_DROPHILITED;
1805 if (info.m_state & wxLIST_STATE_DROPHILITED)
1806 lvItem.state |= LVIS_DROPHILITED;
1807 }
1808 if (info.m_stateMask & wxLIST_STATE_FOCUSED)
1809 {
1810 lvItem.stateMask |= LVIS_FOCUSED;
1811 if (info.m_state & wxLIST_STATE_FOCUSED)
1812 lvItem.state |= LVIS_FOCUSED;
1813 }
1814 if (info.m_stateMask & wxLIST_STATE_SELECTED)
1815 {
1816 lvItem.stateMask |= LVIS_SELECTED;
1817 if (info.m_state & wxLIST_STATE_SELECTED)
1818 lvItem.state |= LVIS_SELECTED;
1819 }
acb62b84 1820 }
acb62b84 1821
0b5efdc7 1822 if (info.m_mask & wxLIST_MASK_TEXT)
acb62b84 1823 {
edccf428 1824 lvItem.mask |= LVIF_TEXT;
0b5efdc7
VZ
1825 if ( ctrl->GetWindowStyleFlag() & wxLC_USER_TEXT )
1826 {
1827 lvItem.pszText = LPSTR_TEXTCALLBACK;
1828 }
1829 else
1830 {
edccf428 1831 lvItem.pszText = WXSTRINGCAST info.m_text;
0b5efdc7
VZ
1832 if ( lvItem.pszText )
1833 lvItem.cchTextMax = info.m_text.Length();
1834 else
1835 lvItem.cchTextMax = 0;
1836 }
acb62b84 1837 }
0b5efdc7 1838 if (info.m_mask & wxLIST_MASK_IMAGE)
edccf428 1839 lvItem.mask |= LVIF_IMAGE;
0b5efdc7 1840 if (info.m_mask & wxLIST_MASK_DATA)
edccf428 1841 lvItem.mask |= LVIF_PARAM;
2bda0e17
KB
1842}
1843
edccf428 1844// ----------------------------------------------------------------------------
2bda0e17 1845// List event
edccf428
VZ
1846// ----------------------------------------------------------------------------
1847
92976ab6 1848IMPLEMENT_DYNAMIC_CLASS(wxListEvent, wxNotifyEvent)
2bda0e17 1849
fd3f686c 1850wxListEvent::wxListEvent(wxEventType commandType, int id)
edccf428 1851 : wxNotifyEvent(commandType, id)
2bda0e17 1852{
0b5efdc7
VZ
1853 m_code = 0;
1854 m_itemIndex = 0;
5d47c8a0 1855 m_oldItemIndex = 0;
0b5efdc7
VZ
1856 m_col = 0;
1857 m_cancelled = FALSE;
2bda0e17
KB
1858}
1859
edccf428 1860#endif // __WIN95__
2bda0e17 1861