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