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