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