]> git.saurik.com Git - wxWidgets.git/blame - src/msw/listctrl.cpp
wxMimeTypesManager now supports creating associations as well as querying
[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
1084 // inconsitent with the generic version - so we adjust the index
1085 return ListView_FindItem(GetHwnd(), (int) start - 1, &findInfo);
2bda0e17
KB
1086}
1087
1088// Find an item whose data matches this data, starting from the item after 'start'
1089// or the beginning if 'start' is -1.
debe6624 1090long wxListCtrl::FindItem(long start, long data)
2bda0e17 1091{
0b5efdc7 1092 LV_FINDINFO findInfo;
2bda0e17 1093
0b5efdc7
VZ
1094 findInfo.flags = LVFI_PARAM;
1095 findInfo.lParam = data;
2bda0e17 1096
edccf428 1097 return ListView_FindItem(GetHwnd(), (int) start, & findInfo);
2bda0e17
KB
1098}
1099
1100// Find an item nearest this position in the specified direction, starting from
1101// the item after 'start' or the beginning if 'start' is -1.
debe6624 1102long wxListCtrl::FindItem(long start, const wxPoint& pt, int direction)
2bda0e17 1103{
0b5efdc7 1104 LV_FINDINFO findInfo;
2bda0e17 1105
0b5efdc7
VZ
1106 findInfo.flags = LVFI_NEARESTXY;
1107 findInfo.pt.x = pt.x;
1108 findInfo.pt.y = pt.y;
acb62b84 1109 findInfo.vkDirection = VK_RIGHT;
2bda0e17 1110
0b5efdc7
VZ
1111 if ( direction == wxLIST_FIND_UP )
1112 findInfo.vkDirection = VK_UP;
1113 else if ( direction == wxLIST_FIND_DOWN )
1114 findInfo.vkDirection = VK_DOWN;
1115 else if ( direction == wxLIST_FIND_LEFT )
1116 findInfo.vkDirection = VK_LEFT;
1117 else if ( direction == wxLIST_FIND_RIGHT )
1118 findInfo.vkDirection = VK_RIGHT;
1119
edccf428 1120 return ListView_FindItem(GetHwnd(), (int) start, & findInfo);
2bda0e17
KB
1121}
1122
1123// Determines which item (if any) is at the specified point,
1124// giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1125long wxListCtrl::HitTest(const wxPoint& point, int& flags)
1126{
1127 LV_HITTESTINFO hitTestInfo;
0b5efdc7
VZ
1128 hitTestInfo.pt.x = (int) point.x;
1129 hitTestInfo.pt.y = (int) point.y;
2bda0e17 1130
edccf428 1131 ListView_HitTest(GetHwnd(), & hitTestInfo);
2bda0e17 1132
0b5efdc7
VZ
1133 flags = 0;
1134 if ( hitTestInfo.flags & LVHT_ABOVE )
1135 flags |= wxLIST_HITTEST_ABOVE;
1136 if ( hitTestInfo.flags & LVHT_BELOW )
1137 flags |= wxLIST_HITTEST_BELOW;
1138 if ( hitTestInfo.flags & LVHT_NOWHERE )
1139 flags |= wxLIST_HITTEST_NOWHERE;
1140 if ( hitTestInfo.flags & LVHT_ONITEMICON )
1141 flags |= wxLIST_HITTEST_ONITEMICON;
1142 if ( hitTestInfo.flags & LVHT_ONITEMLABEL )
1143 flags |= wxLIST_HITTEST_ONITEMLABEL;
1144 if ( hitTestInfo.flags & LVHT_ONITEMSTATEICON )
1145 flags |= wxLIST_HITTEST_ONITEMSTATEICON;
1146 if ( hitTestInfo.flags & LVHT_TOLEFT )
1147 flags |= wxLIST_HITTEST_TOLEFT;
1148 if ( hitTestInfo.flags & LVHT_TORIGHT )
1149 flags |= wxLIST_HITTEST_TORIGHT;
1150
edccf428 1151 return (long) hitTestInfo.iItem;
2bda0e17
KB
1152}
1153
1154// Inserts an item, returning the index of the new item if successful,
1155// -1 otherwise.
2bda0e17
KB
1156long wxListCtrl::InsertItem(wxListItem& info)
1157{
0b5efdc7
VZ
1158 LV_ITEM item;
1159 wxConvertToMSWListItem(this, info, item);
2bda0e17 1160
bdc72a22
VZ
1161 // check whether it has any custom attributes
1162 if ( info.HasAttributes() )
1163 {
2702ed5a 1164
35ec54d3
VS
1165 wxListItemAttr *attr;
1166 attr = (wxListItemAttr*) m_attrs.Get(item.iItem);
2702ed5a 1167
35ec54d3 1168 if (attr == NULL)
2702ed5a 1169
35ec54d3 1170 m_attrs.Put(item.iItem, (wxObject *)new wxListItemAttr(*info.GetAttributes()));
2702ed5a 1171
35ec54d3 1172 else *attr = *info.GetAttributes();
bdc72a22
VZ
1173
1174 m_hasAnyAttr = TRUE;
1175 }
bdc72a22 1176
edccf428 1177 return (long) ListView_InsertItem(GetHwnd(), & item);
2bda0e17
KB
1178}
1179
debe6624 1180long wxListCtrl::InsertItem(long index, const wxString& label)
2bda0e17 1181{
0b5efdc7
VZ
1182 wxListItem info;
1183 info.m_text = label;
1184 info.m_mask = wxLIST_MASK_TEXT;
1185 info.m_itemId = index;
1186 return InsertItem(info);
2bda0e17
KB
1187}
1188
1189// Inserts an image item
debe6624 1190long wxListCtrl::InsertItem(long index, int imageIndex)
2bda0e17 1191{
0b5efdc7
VZ
1192 wxListItem info;
1193 info.m_image = imageIndex;
1194 info.m_mask = wxLIST_MASK_IMAGE;
1195 info.m_itemId = index;
1196 return InsertItem(info);
2bda0e17
KB
1197}
1198
1199// Inserts an image/string item
debe6624 1200long wxListCtrl::InsertItem(long index, const wxString& label, int imageIndex)
2bda0e17 1201{
0b5efdc7
VZ
1202 wxListItem info;
1203 info.m_image = imageIndex;
1204 info.m_text = label;
1205 info.m_mask = wxLIST_MASK_IMAGE | wxLIST_MASK_TEXT;
1206 info.m_itemId = index;
1207 return InsertItem(info);
2bda0e17
KB
1208}
1209
1210// For list view mode (only), inserts a column.
debe6624 1211long wxListCtrl::InsertColumn(long col, wxListItem& item)
2bda0e17 1212{
0b5efdc7
VZ
1213 LV_COLUMN lvCol;
1214 lvCol.mask = 0;
1215 lvCol.fmt = 0;
1216 lvCol.pszText = NULL;
1217
1218 if ( item.m_mask & wxLIST_MASK_TEXT )
1219 {
1220 lvCol.mask |= LVCF_TEXT;
1221 lvCol.pszText = WXSTRINGCAST item.m_text;
1222 lvCol.cchTextMax = 0; // Ignored
1223 }
1224 if ( item.m_mask & wxLIST_MASK_FORMAT )
1225 {
1226 lvCol.mask |= LVCF_FMT;
1227
1228 if ( item.m_format == wxLIST_FORMAT_LEFT )
1229 lvCol.fmt = LVCFMT_LEFT;
1230 if ( item.m_format == wxLIST_FORMAT_RIGHT )
1231 lvCol.fmt = LVCFMT_RIGHT;
1232 if ( item.m_format == wxLIST_FORMAT_CENTRE )
1233 lvCol.fmt = LVCFMT_CENTER;
2bda0e17
KB
1234 }
1235
e373f51b 1236 lvCol.mask |= LVCF_WIDTH;
0b5efdc7
VZ
1237 if ( item.m_mask & wxLIST_MASK_WIDTH )
1238 {
e373f51b 1239 if ( item.m_width == wxLIST_AUTOSIZE)
0b5efdc7 1240 lvCol.cx = LVSCW_AUTOSIZE;
e373f51b 1241 else if ( item.m_width == wxLIST_AUTOSIZE_USEHEADER)
0b5efdc7 1242 lvCol.cx = LVSCW_AUTOSIZE_USEHEADER;
e373f51b
VZ
1243 else
1244 lvCol.cx = item.m_width;
1245 }
1246 else
1247 {
1248 // always give some width to the new column: this one is compatible
1249 // with wxGTK
1250 lvCol.cx = 80;
0b5efdc7 1251 }
e373f51b 1252
0b5efdc7
VZ
1253 lvCol.mask |= LVCF_SUBITEM;
1254 lvCol.iSubItem = col;
2bda0e17 1255
edccf428 1256 bool success = ListView_InsertColumn(GetHwnd(), col, & lvCol) != -1;
2bda0e17 1257 if ( success )
e373f51b
VZ
1258 {
1259 m_colCount++;
1260 }
1261 else
1262 {
223d09f6 1263 wxLogDebug(wxT("Failed to insert the column '%s' into listview!"),
e373f51b
VZ
1264 lvCol.pszText);
1265 }
1266
2bda0e17
KB
1267 return success;
1268}
1269
bdc72a22
VZ
1270long wxListCtrl::InsertColumn(long col,
1271 const wxString& heading,
1272 int format,
1273 int width)
2bda0e17 1274{
0b5efdc7
VZ
1275 wxListItem item;
1276 item.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_FORMAT;
1277 item.m_text = heading;
1278 if ( width > -1 )
1279 {
1280 item.m_mask |= wxLIST_MASK_WIDTH;
1281 item.m_width = width;
1282 }
1283 item.m_format = format;
2bda0e17 1284
0b5efdc7 1285 return InsertColumn(col, item);
2bda0e17
KB
1286}
1287
1288// Scrolls the list control. If in icon, small icon or report view mode,
1289// x specifies the number of pixels to scroll. If in list view mode, x
1290// specifies the number of columns to scroll.
1291// If in icon, small icon or list view mode, y specifies the number of pixels
1292// to scroll. If in report view mode, y specifies the number of lines to scroll.
debe6624 1293bool wxListCtrl::ScrollList(int dx, int dy)
2bda0e17 1294{
edccf428 1295 return (ListView_Scroll(GetHwnd(), dx, dy) != 0);
2bda0e17
KB
1296}
1297
1298// Sort items.
1299
1300// fn is a function which takes 3 long arguments: item1, item2, data.
1301// item1 is the long data associated with a first item (NOT the index).
1302// item2 is the long data associated with a second item (NOT the index).
1303// data is the same value as passed to SortItems.
1304// The return value is a negative number if the first item should precede the second
1305// item, a positive number of the second item should precede the first,
1306// or zero if the two items are equivalent.
1307
1308// data is arbitrary data to be passed to the sort function.
1309bool wxListCtrl::SortItems(wxListCtrlCompare fn, long data)
1310{
edccf428 1311 return (ListView_SortItems(GetHwnd(), (PFNLVCOMPARE) fn, data) != 0);
2bda0e17
KB
1312}
1313
edccf428
VZ
1314// ----------------------------------------------------------------------------
1315// message processing
1316// ----------------------------------------------------------------------------
1317
debe6624 1318bool wxListCtrl::MSWCommand(WXUINT cmd, WXWORD id)
2bda0e17 1319{
0b5efdc7 1320 if (cmd == EN_UPDATE)
acb62b84 1321 {
0b5efdc7
VZ
1322 wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, id);
1323 event.SetEventObject( this );
1324 ProcessCommand(event);
1325 return TRUE;
acb62b84 1326 }
0b5efdc7 1327 else if (cmd == EN_KILLFOCUS)
acb62b84 1328 {
0b5efdc7
VZ
1329 wxCommandEvent event(wxEVT_KILL_FOCUS, id);
1330 event.SetEventObject( this );
1331 ProcessCommand(event);
1332 return TRUE;
acb62b84 1333 }
edccf428
VZ
1334 else
1335 return FALSE;
0b5efdc7
VZ
1336}
1337
a23fd0e1 1338bool wxListCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
0b5efdc7 1339{
bdc72a22
VZ
1340 // prepare the event
1341 // -----------------
1342
0b5efdc7
VZ
1343 wxListEvent event(wxEVT_NULL, m_windowId);
1344 wxEventType eventType = wxEVT_NULL;
225fe9d6 1345
bdc72a22 1346 NMHDR *nmhdr = (NMHDR *)lParam;
225fe9d6
VZ
1347
1348 // almost all messages use NM_LISTVIEW
1349 NM_LISTVIEW *nmLV = (NM_LISTVIEW *)nmhdr;
1350
1351 // this is true for almost all events
1352 event.m_item.m_data = nmLV->lParam;
1353
bdc72a22 1354 switch ( nmhdr->code )
acb62b84 1355 {
0b5efdc7 1356 case LVN_BEGINRDRAG:
bdc72a22 1357 eventType = wxEVT_COMMAND_LIST_BEGIN_RDRAG;
0b5efdc7 1358 // fall through
cb0f56f9 1359
0b5efdc7
VZ
1360 case LVN_BEGINDRAG:
1361 if ( eventType == wxEVT_NULL )
1362 {
1363 eventType = wxEVT_COMMAND_LIST_BEGIN_DRAG;
1364 }
1365
225fe9d6
VZ
1366 event.m_itemIndex = nmLV->iItem;
1367 event.m_pointDrag.x = nmLV->ptAction.x;
1368 event.m_pointDrag.y = nmLV->ptAction.y;
0b5efdc7
VZ
1369 break;
1370
1371 case LVN_BEGINLABELEDIT:
1372 {
1373 eventType = wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT;
1374 LV_DISPINFO *info = (LV_DISPINFO *)lParam;
edccf428 1375 wxConvertFromMSWListItem(this, event.m_item, info->item, GetHwnd());
0b5efdc7 1376 }
225fe9d6 1377 break;
0b5efdc7
VZ
1378
1379 case LVN_COLUMNCLICK:
225fe9d6
VZ
1380 eventType = wxEVT_COMMAND_LIST_COL_CLICK;
1381 event.m_itemIndex = -1;
1382 event.m_col = nmLV->iSubItem;
1383 break;
5ea47806 1384
0b5efdc7 1385 case LVN_DELETEALLITEMS:
6932a32c 1386 eventType = wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS;
5ea47806 1387 event.m_itemIndex = -1;
5ea47806 1388
6932a32c 1389 FreeAllAttrs();
bdc72a22 1390
6932a32c 1391 break;
5ea47806 1392
0b5efdc7 1393 case LVN_DELETEITEM:
225fe9d6
VZ
1394 eventType = wxEVT_COMMAND_LIST_DELETE_ITEM;
1395 event.m_itemIndex = nmLV->iItem;
bdc72a22 1396
225fe9d6
VZ
1397 if ( m_hasAnyAttr )
1398 {
1399 delete (wxListItemAttr *)m_attrs.Delete(nmLV->iItem);
0b5efdc7 1400 }
bdc72a22
VZ
1401 break;
1402
0b5efdc7
VZ
1403 case LVN_ENDLABELEDIT:
1404 {
1405 eventType = wxEVT_COMMAND_LIST_END_LABEL_EDIT;
1406 LV_DISPINFO *info = (LV_DISPINFO *)lParam;
1ee4ead5 1407 wxConvertFromMSWListItem(this, event.m_item, info->item);
0b5efdc7 1408 if ( info->item.pszText == NULL || info->item.iItem == -1 )
1ee4ead5 1409 return FALSE;
0b5efdc7 1410 }
bdc72a22
VZ
1411 break;
1412
1413 case LVN_SETDISPINFO:
1414 {
1415 eventType = wxEVT_COMMAND_LIST_SET_INFO;
1416 LV_DISPINFO *info = (LV_DISPINFO *)lParam;
1417 wxConvertFromMSWListItem(this, event.m_item, info->item, GetHwnd());
1418 }
1419 break;
edccf428 1420
bdc72a22 1421 case LVN_GETDISPINFO:
edccf428
VZ
1422 // this provokes stack overflow: indeed, wxConvertFromMSWListItem()
1423 // sends us WM_NOTIFY! As it doesn't do anything for now, just leave
1424 // it out.
1425#if 0
0b5efdc7 1426 {
0b5efdc7
VZ
1427 // TODO: some text buffering here, I think
1428 // TODO: API for getting Windows to retrieve values
1429 // on demand.
1430 eventType = wxEVT_COMMAND_LIST_GET_INFO;
1431 LV_DISPINFO *info = (LV_DISPINFO *)lParam;
edccf428 1432 wxConvertFromMSWListItem(this, event.m_item, info->item, GetHwnd());
0b5efdc7
VZ
1433 break;
1434 }
edccf428 1435#endif // 0
bdc72a22
VZ
1436 return FALSE;
1437
edccf428 1438
0b5efdc7 1439 case LVN_INSERTITEM:
225fe9d6
VZ
1440 eventType = wxEVT_COMMAND_LIST_INSERT_ITEM;
1441 event.m_itemIndex = nmLV->iItem;
1442 break;
bdc72a22 1443
0b5efdc7 1444 case LVN_ITEMCHANGED:
225fe9d6
VZ
1445 // This needs to be sent to wxListCtrl as a rather more concrete
1446 // event. For now, just detect a selection or deselection.
1447 if ( (nmLV->uNewState & LVIS_SELECTED) && !(nmLV->uOldState & LVIS_SELECTED) )
0b5efdc7 1448 {
225fe9d6
VZ
1449 eventType = wxEVT_COMMAND_LIST_ITEM_SELECTED;
1450 event.m_itemIndex = nmLV->iItem;
1451 }
1452 else if ( !(nmLV->uNewState & LVIS_SELECTED) && (nmLV->uOldState & LVIS_SELECTED) )
1453 {
1454 eventType = wxEVT_COMMAND_LIST_ITEM_DESELECTED;
1455 event.m_itemIndex = nmLV->iItem;
0b5efdc7 1456 }
225fe9d6
VZ
1457 else
1458 {
1459 return FALSE;
1460 }
1461 break;
edccf428 1462
0b5efdc7
VZ
1463 case LVN_KEYDOWN:
1464 {
0b5efdc7 1465 LV_KEYDOWN *info = (LV_KEYDOWN *)lParam;
edccf428
VZ
1466 WORD wVKey = info->wVKey;
1467
1468 // get the current selection
1469 long lItem = GetNextItem(-1,
1470 wxLIST_NEXT_ALL,
1471 wxLIST_STATE_SELECTED);
1472
1473 // <Enter> or <Space> activate the selected item if any
1474 if ( lItem != -1 && (wVKey == VK_RETURN || wVKey == VK_SPACE) )
1475 {
1476 // TODO this behaviour probably should be optional
1477 eventType = wxEVT_COMMAND_LIST_ITEM_ACTIVATED;
1478 event.m_itemIndex = lItem;
1479 }
1480 else
1481 {
1482 eventType = wxEVT_COMMAND_LIST_KEY_DOWN;
1483 event.m_code = wxCharCodeMSWToWX(wVKey);
1484 }
225fe9d6 1485
f6bcfd97
BP
1486 if ( lItem != -1 )
1487 {
1488 // fill the other fields too
1489 event.m_item.m_text = GetItemText(lItem);
1490 event.m_item.m_data = GetItemData(lItem);
1491 }
0b5efdc7 1492 }
225fe9d6 1493 break;
edccf428
VZ
1494
1495 case NM_DBLCLK:
1496 // if the user processes it in wxEVT_COMMAND_LEFT_CLICK(), don't do
1497 // anything else
1498 if ( wxControl::MSWOnNotify(idCtrl, lParam, result) )
1499 {
1500 return TRUE;
1501 }
1502
1503 // else translate it into wxEVT_COMMAND_LIST_ITEM_ACTIVATED event
5bd3a2da 1504 // if it happened on an item (and not on empty place)
225fe9d6 1505 if ( nmLV->iItem == -1 )
1ee4ead5 1506 {
225fe9d6
VZ
1507 // not on item
1508 return FALSE;
1ee4ead5 1509 }
225fe9d6
VZ
1510
1511 eventType = wxEVT_COMMAND_LIST_ITEM_ACTIVATED;
1512 event.m_itemIndex = nmLV->iItem;
f6bcfd97 1513 event.m_item.m_text = GetItemText(nmLV->iItem);
225fe9d6 1514 event.m_item.m_data = GetItemData(nmLV->iItem);
edccf428 1515 break;
cb0f56f9
VZ
1516
1517 case NM_RCLICK:
225fe9d6
VZ
1518 /* TECH NOTE: NM_RCLICK isn't really good enough here. We want to
1519 subclass and check for the actual WM_RBUTTONDOWN message,
1520 because NM_RCLICK waits for the WM_RBUTTONUP message as well
1521 before firing off. We want to have notify events for both down
1522 -and- up. */
1523 {
1524 // if the user processes it in wxEVT_COMMAND_RIGHT_CLICK(),
1525 // don't do anything else
1526 if ( wxControl::MSWOnNotify(idCtrl, lParam, result) )
1527 {
1528 return TRUE;
1529 }
cb0f56f9 1530
225fe9d6
VZ
1531 // else translate it into wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK event
1532 LV_HITTESTINFO lvhti;
1533 wxZeroMemory(lvhti);
11c7d5b6 1534
225fe9d6
VZ
1535 ::GetCursorPos(&(lvhti.pt));
1536 ::ScreenToClient(GetHwnd(),&(lvhti.pt));
1537 if ( ListView_HitTest(GetHwnd(),&lvhti) != -1 )
cb0f56f9 1538 {
225fe9d6
VZ
1539 if ( lvhti.flags & LVHT_ONITEM )
1540 {
1541 eventType = wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK;
1542 event.m_itemIndex = lvhti.iItem;
a1f79c1e
VZ
1543 event.m_pointDrag.x = lvhti.pt.x;
1544 event.m_pointDrag.y = lvhti.pt.y;
225fe9d6 1545 }
cb0f56f9 1546 }
9bfa7bfc 1547 }
cb0f56f9
VZ
1548 break;
1549
bdc72a22
VZ
1550#if 0
1551 case NM_MCLICK: // ***** THERE IS NO NM_MCLICK. Subclass anyone? ******
1552 {
1553 // if the user processes it in wxEVT_COMMAND_MIDDLE_CLICK(), don't do
1554 // anything else
1555 if ( wxControl::MSWOnNotify(idCtrl, lParam, result) )
1556 {
1557 return TRUE;
1558 }
cb0f56f9 1559
bdc72a22
VZ
1560 // else translate it into wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK event
1561 eventType = wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK;
1562 NMITEMACTIVATE* hdr = (NMITEMACTIVATE*)lParam;
1563 event.m_itemIndex = hdr->iItem;
1564 }
1565 break;
1566#endif // 0
1567
6ecfe2ac 1568#if defined(_WIN32_IE) && _WIN32_IE >= 0x300
bdc72a22 1569 case NM_CUSTOMDRAW:
0b5efdc7 1570 {
bdc72a22
VZ
1571 LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)lParam;
1572 NMCUSTOMDRAW& nmcd = lplvcd->nmcd;
1573 switch( nmcd.dwDrawStage )
1574 {
d62228a6 1575 case CDDS_PREPAINT:
bdc72a22
VZ
1576 // if we've got any items with non standard attributes,
1577 // notify us before painting each item
1578 *result = m_hasAnyAttr ? CDRF_NOTIFYITEMDRAW
1579 : CDRF_DODEFAULT;
1580 return TRUE;
1581
1582 case CDDS_ITEMPREPAINT:
1583 {
d62228a6
VZ
1584 wxListItemAttr *attr =
1585 (wxListItemAttr *)m_attrs.Get(nmcd.dwItemSpec);
1586
1587 if ( !attr )
bdc72a22
VZ
1588 {
1589 // nothing to do for this item
1590 return CDRF_DODEFAULT;
1591 }
1592
d62228a6
VZ
1593 HFONT hFont;
1594 wxColour colText, colBack;
1595 if ( attr->HasFont() )
1596 {
1597 wxFont font = attr->GetFont();
1598 hFont = (HFONT)font.GetResourceHandle();
1599 }
1600 else
1601 {
1602 hFont = 0;
1603 }
1604
1605 if ( attr->HasTextColour() )
1606 {
1607 colText = attr->GetTextColour();
1608 }
1609 else
1610 {
1611 colText = GetTextColour();
1612 }
1613
1614 if ( attr->HasBackgroundColour() )
1615 {
1616 colBack = attr->GetBackgroundColour();
1617 }
1618 else
1619 {
1620 colBack = GetBackgroundColour();
1621 }
1622
1623 // note that if we wanted to set colours for
1624 // individual columns (subitems), we would have
1625 // returned CDRF_NOTIFYSUBITEMREDRAW from here
1626 if ( hFont )
1627 {
1628 ::SelectObject(nmcd.hdc, hFont);
bdc72a22 1629
d62228a6
VZ
1630 *result = CDRF_NEWFONT;
1631 }
1632 else
1633 {
1634 *result = CDRF_DODEFAULT;
1635 }
bdc72a22 1636
d62228a6
VZ
1637 lplvcd->clrText = wxColourToRGB(colText);
1638 lplvcd->clrTextBk = wxColourToRGB(colBack);
bdc72a22
VZ
1639
1640 return TRUE;
1641 }
d62228a6
VZ
1642
1643 default:
1644 *result = CDRF_DODEFAULT;
1645 return TRUE;
bdc72a22 1646 }
0b5efdc7 1647 }
bdc72a22 1648 break;
6ecfe2ac 1649#endif // _WIN32_IE >= 0x300
0b5efdc7 1650
edccf428 1651 default:
a23fd0e1 1652 return wxControl::MSWOnNotify(idCtrl, lParam, result);
acb62b84
VZ
1653 }
1654
bdc72a22
VZ
1655 // process the event
1656 // -----------------
1657
0b5efdc7
VZ
1658 event.SetEventObject( this );
1659 event.SetEventType(eventType);
acb62b84 1660
0b5efdc7
VZ
1661 if ( !GetEventHandler()->ProcessEvent(event) )
1662 return FALSE;
acb62b84 1663
bdc72a22
VZ
1664 // post processing
1665 // ---------------
1666
225fe9d6 1667 switch ( nmhdr->code )
acb62b84 1668 {
6932a32c
VZ
1669 case LVN_DELETEALLITEMS:
1670 // always return TRUE to suppress all additional LVN_DELETEITEM
1671 // notifications - this makes deleting all items from a list ctrl
1672 // much faster
1673 *result = TRUE;
1674
1675 return TRUE;
1676
1ee4ead5 1677 case LVN_GETDISPINFO:
0b5efdc7 1678 {
1ee4ead5
VZ
1679 LV_DISPINFO *info = (LV_DISPINFO *)lParam;
1680 if ( info->item.mask & LVIF_TEXT )
1681 {
1682 if ( !event.m_item.m_text.IsNull() )
1683 {
1684 info->item.pszText = AddPool(event.m_item.m_text);
1685 info->item.cchTextMax = wxStrlen(info->item.pszText) + 1;
1686 }
1687 }
1688 // wxConvertToMSWListItem(this, event.m_item, info->item);
1689 break;
0b5efdc7 1690 }
1ee4ead5
VZ
1691 case LVN_ENDLABELEDIT:
1692 {
1693 *result = event.IsAllowed();
1694 return TRUE;
1695 }
acb62b84 1696 }
acb62b84 1697
0b5efdc7 1698 *result = !event.IsAllowed();
fd3f686c 1699
0b5efdc7 1700 return TRUE;
2bda0e17
KB
1701}
1702
837e5743 1703wxChar *wxListCtrl::AddPool(const wxString& str)
2bda0e17 1704{
0b5efdc7
VZ
1705 // Remove the first element if 3 strings exist
1706 if ( m_stringPool.Number() == 3 )
1707 {
1708 wxNode *node = m_stringPool.First();
1709 delete[] (char *)node->Data();
1710 delete node;
1711 }
837e5743
OK
1712 wxNode *node = m_stringPool.Add(WXSTRINGCAST str);
1713 return (wxChar *)node->Data();
2bda0e17
KB
1714}
1715
2702ed5a
JS
1716// Necessary for drawing hrules and vrules, if specified
1717void wxListCtrl::OnPaint(wxPaintEvent& event)
1718{
1719 wxPaintDC dc(this);
1720
1721 wxControl::OnPaint(event);
1722
1723 // Reset the device origin since it may have been set
1724 dc.SetDeviceOrigin(0, 0);
1725
1726 bool drawHRules = ((GetWindowStyle() & wxLC_HRULES) != 0);
1727 bool drawVRules = ((GetWindowStyle() & wxLC_VRULES) != 0);
1728
1729 if (!drawHRules && !drawVRules)
1730 return;
1731 if ((GetWindowStyle() & wxLC_REPORT) == 0)
1732 return;
1733
1734 wxPen pen(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT), 1, wxSOLID);
1735 dc.SetPen(pen);
1736 dc.SetBrush(* wxTRANSPARENT_BRUSH);
1737
1738 wxSize clientSize = GetClientSize();
1739 wxRect itemRect;
1740 int cy=0;
1741
2702ed5a
JS
1742 int itemCount = GetItemCount();
1743 int i;
1744 for (i = 0; i < itemCount; i++)
1745 {
1746 if (GetItemRect(i, itemRect))
1747 {
1748 cy = itemRect.GetTop();
1749 if (i != 0) // Don't draw the first one
1750 {
1751 dc.DrawLine(0, cy, clientSize.x, cy);
1752
1753 // Draw last line
1754 if (i == (GetItemCount() - 1))
1755 {
1756 cy = itemRect.GetBottom();
1757 dc.DrawLine(0, cy, clientSize.x, cy);
1758 }
1759 }
1760 }
1761 }
1762 i = (GetItemCount() - 1);
1763 if (drawVRules && (i > -1))
1764 {
1765 wxRect firstItemRect;
1766 GetItemRect(0, firstItemRect);
1767
1768 if (GetItemRect(i, itemRect))
1769 {
1770 int col;
1771 int x = itemRect.GetX();
1772 for (col = 0; col < GetColumnCount(); col++)
1773 {
1774 int colWidth = GetColumnWidth(col);
1775 x += colWidth ;
1776 dc.DrawLine(x, firstItemRect.GetY() - 2, x, itemRect.GetBottom());
1777 }
1778 }
1779 }
1780}
1781
edccf428
VZ
1782// ----------------------------------------------------------------------------
1783// wxListItem
1784// ----------------------------------------------------------------------------
1785
2bda0e17 1786// List item structure
0b5efdc7 1787wxListItem::wxListItem()
2bda0e17
KB
1788{
1789 m_mask = 0;
1790 m_itemId = 0;
1791 m_col = 0;
1792 m_state = 0;
1793 m_stateMask = 0;
1794 m_image = 0;
0b5efdc7 1795 m_data = 0;
2bda0e17 1796
0b5efdc7
VZ
1797 m_format = wxLIST_FORMAT_CENTRE;
1798 m_width = 0;
bdc72a22
VZ
1799
1800 m_attr = NULL;
2bda0e17
KB
1801}
1802
9b00bb16
RR
1803void wxListItem::Clear()
1804{
1805 m_mask = 0;
1806 m_itemId = 0;
1807 m_col = 0;
1808 m_state = 0;
1809 m_stateMask = 0;
1810 m_image = 0;
1811 m_data = 0;
1812 m_format = wxLIST_FORMAT_CENTRE;
1813 m_width = 0;
1814 m_text = wxEmptyString;
1815
1816 if (m_attr) delete m_attr;
1817 m_attr = NULL;
1818}
1819
1820void wxListItem::ClearAttributes()
1821{
1822 if (m_attr) delete m_attr;
1823 m_attr = NULL;
1824}
1825
2bda0e17
KB
1826static void wxConvertFromMSWListItem(const wxListCtrl *ctrl, wxListItem& info, LV_ITEM& lvItem, HWND getFullInfo)
1827{
0b5efdc7
VZ
1828 info.m_data = lvItem.lParam;
1829 info.m_mask = 0;
1830 info.m_state = 0;
1831 info.m_stateMask = 0;
1832 info.m_itemId = lvItem.iItem;
acb62b84 1833
0b5efdc7 1834 long oldMask = lvItem.mask;
acb62b84 1835
0b5efdc7
VZ
1836 bool needText = FALSE;
1837 if (getFullInfo != 0)
acb62b84 1838 {
0b5efdc7
VZ
1839 if ( lvItem.mask & LVIF_TEXT )
1840 needText = FALSE;
1841 else
1842 needText = TRUE;
acb62b84 1843
0b5efdc7
VZ
1844 if ( needText )
1845 {
837e5743 1846 lvItem.pszText = new wxChar[513];
0b5efdc7
VZ
1847 lvItem.cchTextMax = 512;
1848 }
edccf428
VZ
1849 // lvItem.mask |= TVIF_HANDLE | TVIF_STATE | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_CHILDREN | TVIF_PARAM;
1850 lvItem.mask |= LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
1851 ::SendMessage(getFullInfo, LVM_GETITEM, 0, (LPARAM)& lvItem);
0b5efdc7 1852 }
acb62b84 1853
0b5efdc7 1854 if ( lvItem.mask & LVIF_STATE )
acb62b84 1855 {
0b5efdc7
VZ
1856 info.m_mask |= wxLIST_MASK_STATE;
1857
1858 if ( lvItem.stateMask & LVIS_CUT)
1859 {
edccf428 1860 info.m_stateMask |= wxLIST_STATE_CUT;
0b5efdc7 1861 if ( lvItem.state & LVIS_CUT )
edccf428 1862 info.m_state |= wxLIST_STATE_CUT;
0b5efdc7
VZ
1863 }
1864 if ( lvItem.stateMask & LVIS_DROPHILITED)
1865 {
edccf428 1866 info.m_stateMask |= wxLIST_STATE_DROPHILITED;
0b5efdc7 1867 if ( lvItem.state & LVIS_DROPHILITED )
edccf428 1868 info.m_state |= wxLIST_STATE_DROPHILITED;
0b5efdc7
VZ
1869 }
1870 if ( lvItem.stateMask & LVIS_FOCUSED)
1871 {
edccf428 1872 info.m_stateMask |= wxLIST_STATE_FOCUSED;
0b5efdc7 1873 if ( lvItem.state & LVIS_FOCUSED )
edccf428 1874 info.m_state |= wxLIST_STATE_FOCUSED;
0b5efdc7
VZ
1875 }
1876 if ( lvItem.stateMask & LVIS_SELECTED)
1877 {
edccf428 1878 info.m_stateMask |= wxLIST_STATE_SELECTED;
0b5efdc7 1879 if ( lvItem.state & LVIS_SELECTED )
edccf428 1880 info.m_state |= wxLIST_STATE_SELECTED;
0b5efdc7 1881 }
acb62b84 1882 }
0b5efdc7
VZ
1883
1884 if ( lvItem.mask & LVIF_TEXT )
acb62b84 1885 {
0b5efdc7
VZ
1886 info.m_mask |= wxLIST_MASK_TEXT;
1887 info.m_text = lvItem.pszText;
acb62b84 1888 }
0b5efdc7 1889 if ( lvItem.mask & LVIF_IMAGE )
acb62b84 1890 {
0b5efdc7
VZ
1891 info.m_mask |= wxLIST_MASK_IMAGE;
1892 info.m_image = lvItem.iImage;
acb62b84 1893 }
0b5efdc7
VZ
1894 if ( lvItem.mask & LVIF_PARAM )
1895 info.m_mask |= wxLIST_MASK_DATA;
1896 if ( lvItem.mask & LVIF_DI_SETITEM )
1897 info.m_mask |= wxLIST_SET_ITEM;
1898 info.m_col = lvItem.iSubItem;
1899
1900 if (needText)
acb62b84 1901 {
0b5efdc7
VZ
1902 if (lvItem.pszText)
1903 delete[] lvItem.pszText;
acb62b84 1904 }
edccf428 1905 lvItem.mask = oldMask;
2bda0e17
KB
1906}
1907
1908static void wxConvertToMSWListItem(const wxListCtrl *ctrl, wxListItem& info, LV_ITEM& lvItem)
1909{
edccf428 1910 lvItem.iItem = (int) info.m_itemId;
acb62b84 1911
edccf428 1912 lvItem.iImage = info.m_image;
0b5efdc7
VZ
1913 lvItem.lParam = info.m_data;
1914 lvItem.stateMask = 0;
1915 lvItem.state = 0;
1916 lvItem.mask = 0;
1917 lvItem.iSubItem = info.m_col;
acb62b84 1918
0b5efdc7 1919 if (info.m_mask & wxLIST_MASK_STATE)
acb62b84 1920 {
edccf428 1921 lvItem.mask |= LVIF_STATE;
0b5efdc7
VZ
1922 if (info.m_stateMask & wxLIST_STATE_CUT)
1923 {
edccf428 1924 lvItem.stateMask |= LVIS_CUT;
0b5efdc7
VZ
1925 if (info.m_state & wxLIST_STATE_CUT)
1926 lvItem.state |= LVIS_CUT;
1927 }
1928 if (info.m_stateMask & wxLIST_STATE_DROPHILITED)
1929 {
1930 lvItem.stateMask |= LVIS_DROPHILITED;
1931 if (info.m_state & wxLIST_STATE_DROPHILITED)
1932 lvItem.state |= LVIS_DROPHILITED;
1933 }
1934 if (info.m_stateMask & wxLIST_STATE_FOCUSED)
1935 {
1936 lvItem.stateMask |= LVIS_FOCUSED;
1937 if (info.m_state & wxLIST_STATE_FOCUSED)
1938 lvItem.state |= LVIS_FOCUSED;
1939 }
1940 if (info.m_stateMask & wxLIST_STATE_SELECTED)
1941 {
1942 lvItem.stateMask |= LVIS_SELECTED;
1943 if (info.m_state & wxLIST_STATE_SELECTED)
1944 lvItem.state |= LVIS_SELECTED;
1945 }
acb62b84 1946 }
acb62b84 1947
0b5efdc7 1948 if (info.m_mask & wxLIST_MASK_TEXT)
acb62b84 1949 {
edccf428 1950 lvItem.mask |= LVIF_TEXT;
0b5efdc7
VZ
1951 if ( ctrl->GetWindowStyleFlag() & wxLC_USER_TEXT )
1952 {
1953 lvItem.pszText = LPSTR_TEXTCALLBACK;
1954 }
1955 else
1956 {
edccf428 1957 lvItem.pszText = WXSTRINGCAST info.m_text;
0b5efdc7
VZ
1958 if ( lvItem.pszText )
1959 lvItem.cchTextMax = info.m_text.Length();
1960 else
1961 lvItem.cchTextMax = 0;
1962 }
acb62b84 1963 }
0b5efdc7 1964 if (info.m_mask & wxLIST_MASK_IMAGE)
edccf428 1965 lvItem.mask |= LVIF_IMAGE;
0b5efdc7 1966 if (info.m_mask & wxLIST_MASK_DATA)
edccf428 1967 lvItem.mask |= LVIF_PARAM;
2bda0e17
KB
1968}
1969
edccf428 1970// ----------------------------------------------------------------------------
2bda0e17 1971// List event
edccf428
VZ
1972// ----------------------------------------------------------------------------
1973
92976ab6 1974IMPLEMENT_DYNAMIC_CLASS(wxListEvent, wxNotifyEvent)
2bda0e17 1975
fd3f686c 1976wxListEvent::wxListEvent(wxEventType commandType, int id)
edccf428 1977 : wxNotifyEvent(commandType, id)
2bda0e17 1978{
0b5efdc7
VZ
1979 m_code = 0;
1980 m_itemIndex = 0;
5d47c8a0 1981 m_oldItemIndex = 0;
0b5efdc7
VZ
1982 m_col = 0;
1983 m_cancelled = FALSE;
2bda0e17
KB
1984}
1985
edccf428 1986#endif // __WIN95__
2bda0e17 1987