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