]> git.saurik.com Git - wxWidgets.git/blame - src/msw/listctrl.cpp
linking fix
[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;
1543 }
cb0f56f9 1544 }
9bfa7bfc 1545 }
cb0f56f9
VZ
1546 break;
1547
bdc72a22
VZ
1548#if 0
1549 case NM_MCLICK: // ***** THERE IS NO NM_MCLICK. Subclass anyone? ******
1550 {
1551 // if the user processes it in wxEVT_COMMAND_MIDDLE_CLICK(), don't do
1552 // anything else
1553 if ( wxControl::MSWOnNotify(idCtrl, lParam, result) )
1554 {
1555 return TRUE;
1556 }
cb0f56f9 1557
bdc72a22
VZ
1558 // else translate it into wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK event
1559 eventType = wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK;
1560 NMITEMACTIVATE* hdr = (NMITEMACTIVATE*)lParam;
1561 event.m_itemIndex = hdr->iItem;
1562 }
1563 break;
1564#endif // 0
1565
6ecfe2ac 1566#if defined(_WIN32_IE) && _WIN32_IE >= 0x300
bdc72a22 1567 case NM_CUSTOMDRAW:
0b5efdc7 1568 {
bdc72a22
VZ
1569 LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)lParam;
1570 NMCUSTOMDRAW& nmcd = lplvcd->nmcd;
1571 switch( nmcd.dwDrawStage )
1572 {
d62228a6 1573 case CDDS_PREPAINT:
bdc72a22
VZ
1574 // if we've got any items with non standard attributes,
1575 // notify us before painting each item
1576 *result = m_hasAnyAttr ? CDRF_NOTIFYITEMDRAW
1577 : CDRF_DODEFAULT;
1578 return TRUE;
1579
1580 case CDDS_ITEMPREPAINT:
1581 {
d62228a6
VZ
1582 wxListItemAttr *attr =
1583 (wxListItemAttr *)m_attrs.Get(nmcd.dwItemSpec);
1584
1585 if ( !attr )
bdc72a22
VZ
1586 {
1587 // nothing to do for this item
1588 return CDRF_DODEFAULT;
1589 }
1590
d62228a6
VZ
1591 HFONT hFont;
1592 wxColour colText, colBack;
1593 if ( attr->HasFont() )
1594 {
1595 wxFont font = attr->GetFont();
1596 hFont = (HFONT)font.GetResourceHandle();
1597 }
1598 else
1599 {
1600 hFont = 0;
1601 }
1602
1603 if ( attr->HasTextColour() )
1604 {
1605 colText = attr->GetTextColour();
1606 }
1607 else
1608 {
1609 colText = GetTextColour();
1610 }
1611
1612 if ( attr->HasBackgroundColour() )
1613 {
1614 colBack = attr->GetBackgroundColour();
1615 }
1616 else
1617 {
1618 colBack = GetBackgroundColour();
1619 }
1620
1621 // note that if we wanted to set colours for
1622 // individual columns (subitems), we would have
1623 // returned CDRF_NOTIFYSUBITEMREDRAW from here
1624 if ( hFont )
1625 {
1626 ::SelectObject(nmcd.hdc, hFont);
bdc72a22 1627
d62228a6
VZ
1628 *result = CDRF_NEWFONT;
1629 }
1630 else
1631 {
1632 *result = CDRF_DODEFAULT;
1633 }
bdc72a22 1634
d62228a6
VZ
1635 lplvcd->clrText = wxColourToRGB(colText);
1636 lplvcd->clrTextBk = wxColourToRGB(colBack);
bdc72a22
VZ
1637
1638 return TRUE;
1639 }
d62228a6
VZ
1640
1641 default:
1642 *result = CDRF_DODEFAULT;
1643 return TRUE;
bdc72a22 1644 }
0b5efdc7 1645 }
bdc72a22 1646 break;
6ecfe2ac 1647#endif // _WIN32_IE >= 0x300
0b5efdc7 1648
edccf428 1649 default:
a23fd0e1 1650 return wxControl::MSWOnNotify(idCtrl, lParam, result);
acb62b84
VZ
1651 }
1652
bdc72a22
VZ
1653 // process the event
1654 // -----------------
1655
0b5efdc7
VZ
1656 event.SetEventObject( this );
1657 event.SetEventType(eventType);
acb62b84 1658
0b5efdc7
VZ
1659 if ( !GetEventHandler()->ProcessEvent(event) )
1660 return FALSE;
acb62b84 1661
bdc72a22
VZ
1662 // post processing
1663 // ---------------
1664
225fe9d6 1665 switch ( nmhdr->code )
acb62b84 1666 {
6932a32c
VZ
1667 case LVN_DELETEALLITEMS:
1668 // always return TRUE to suppress all additional LVN_DELETEITEM
1669 // notifications - this makes deleting all items from a list ctrl
1670 // much faster
1671 *result = TRUE;
1672
1673 return TRUE;
1674
1ee4ead5 1675 case LVN_GETDISPINFO:
0b5efdc7 1676 {
1ee4ead5
VZ
1677 LV_DISPINFO *info = (LV_DISPINFO *)lParam;
1678 if ( info->item.mask & LVIF_TEXT )
1679 {
1680 if ( !event.m_item.m_text.IsNull() )
1681 {
1682 info->item.pszText = AddPool(event.m_item.m_text);
1683 info->item.cchTextMax = wxStrlen(info->item.pszText) + 1;
1684 }
1685 }
1686 // wxConvertToMSWListItem(this, event.m_item, info->item);
1687 break;
0b5efdc7 1688 }
1ee4ead5
VZ
1689 case LVN_ENDLABELEDIT:
1690 {
1691 *result = event.IsAllowed();
1692 return TRUE;
1693 }
acb62b84 1694 }
acb62b84 1695
0b5efdc7 1696 *result = !event.IsAllowed();
fd3f686c 1697
0b5efdc7 1698 return TRUE;
2bda0e17
KB
1699}
1700
837e5743 1701wxChar *wxListCtrl::AddPool(const wxString& str)
2bda0e17 1702{
0b5efdc7
VZ
1703 // Remove the first element if 3 strings exist
1704 if ( m_stringPool.Number() == 3 )
1705 {
1706 wxNode *node = m_stringPool.First();
1707 delete[] (char *)node->Data();
1708 delete node;
1709 }
837e5743
OK
1710 wxNode *node = m_stringPool.Add(WXSTRINGCAST str);
1711 return (wxChar *)node->Data();
2bda0e17
KB
1712}
1713
2702ed5a
JS
1714// Necessary for drawing hrules and vrules, if specified
1715void wxListCtrl::OnPaint(wxPaintEvent& event)
1716{
1717 wxPaintDC dc(this);
1718
1719 wxControl::OnPaint(event);
1720
1721 // Reset the device origin since it may have been set
1722 dc.SetDeviceOrigin(0, 0);
1723
1724 bool drawHRules = ((GetWindowStyle() & wxLC_HRULES) != 0);
1725 bool drawVRules = ((GetWindowStyle() & wxLC_VRULES) != 0);
1726
1727 if (!drawHRules && !drawVRules)
1728 return;
1729 if ((GetWindowStyle() & wxLC_REPORT) == 0)
1730 return;
1731
1732 wxPen pen(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT), 1, wxSOLID);
1733 dc.SetPen(pen);
1734 dc.SetBrush(* wxTRANSPARENT_BRUSH);
1735
1736 wxSize clientSize = GetClientSize();
1737 wxRect itemRect;
1738 int cy=0;
1739
2702ed5a
JS
1740 int itemCount = GetItemCount();
1741 int i;
1742 for (i = 0; i < itemCount; i++)
1743 {
1744 if (GetItemRect(i, itemRect))
1745 {
1746 cy = itemRect.GetTop();
1747 if (i != 0) // Don't draw the first one
1748 {
1749 dc.DrawLine(0, cy, clientSize.x, cy);
1750
1751 // Draw last line
1752 if (i == (GetItemCount() - 1))
1753 {
1754 cy = itemRect.GetBottom();
1755 dc.DrawLine(0, cy, clientSize.x, cy);
1756 }
1757 }
1758 }
1759 }
1760 i = (GetItemCount() - 1);
1761 if (drawVRules && (i > -1))
1762 {
1763 wxRect firstItemRect;
1764 GetItemRect(0, firstItemRect);
1765
1766 if (GetItemRect(i, itemRect))
1767 {
1768 int col;
1769 int x = itemRect.GetX();
1770 for (col = 0; col < GetColumnCount(); col++)
1771 {
1772 int colWidth = GetColumnWidth(col);
1773 x += colWidth ;
1774 dc.DrawLine(x, firstItemRect.GetY() - 2, x, itemRect.GetBottom());
1775 }
1776 }
1777 }
1778}
1779
edccf428
VZ
1780// ----------------------------------------------------------------------------
1781// wxListItem
1782// ----------------------------------------------------------------------------
1783
2bda0e17 1784// List item structure
0b5efdc7 1785wxListItem::wxListItem()
2bda0e17
KB
1786{
1787 m_mask = 0;
1788 m_itemId = 0;
1789 m_col = 0;
1790 m_state = 0;
1791 m_stateMask = 0;
1792 m_image = 0;
0b5efdc7 1793 m_data = 0;
2bda0e17 1794
0b5efdc7
VZ
1795 m_format = wxLIST_FORMAT_CENTRE;
1796 m_width = 0;
bdc72a22
VZ
1797
1798 m_attr = NULL;
2bda0e17
KB
1799}
1800
9b00bb16
RR
1801void wxListItem::Clear()
1802{
1803 m_mask = 0;
1804 m_itemId = 0;
1805 m_col = 0;
1806 m_state = 0;
1807 m_stateMask = 0;
1808 m_image = 0;
1809 m_data = 0;
1810 m_format = wxLIST_FORMAT_CENTRE;
1811 m_width = 0;
1812 m_text = wxEmptyString;
1813
1814 if (m_attr) delete m_attr;
1815 m_attr = NULL;
1816}
1817
1818void wxListItem::ClearAttributes()
1819{
1820 if (m_attr) delete m_attr;
1821 m_attr = NULL;
1822}
1823
2bda0e17
KB
1824static void wxConvertFromMSWListItem(const wxListCtrl *ctrl, wxListItem& info, LV_ITEM& lvItem, HWND getFullInfo)
1825{
0b5efdc7
VZ
1826 info.m_data = lvItem.lParam;
1827 info.m_mask = 0;
1828 info.m_state = 0;
1829 info.m_stateMask = 0;
1830 info.m_itemId = lvItem.iItem;
acb62b84 1831
0b5efdc7 1832 long oldMask = lvItem.mask;
acb62b84 1833
0b5efdc7
VZ
1834 bool needText = FALSE;
1835 if (getFullInfo != 0)
acb62b84 1836 {
0b5efdc7
VZ
1837 if ( lvItem.mask & LVIF_TEXT )
1838 needText = FALSE;
1839 else
1840 needText = TRUE;
acb62b84 1841
0b5efdc7
VZ
1842 if ( needText )
1843 {
837e5743 1844 lvItem.pszText = new wxChar[513];
0b5efdc7
VZ
1845 lvItem.cchTextMax = 512;
1846 }
edccf428
VZ
1847 // lvItem.mask |= TVIF_HANDLE | TVIF_STATE | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_CHILDREN | TVIF_PARAM;
1848 lvItem.mask |= LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
1849 ::SendMessage(getFullInfo, LVM_GETITEM, 0, (LPARAM)& lvItem);
0b5efdc7 1850 }
acb62b84 1851
0b5efdc7 1852 if ( lvItem.mask & LVIF_STATE )
acb62b84 1853 {
0b5efdc7
VZ
1854 info.m_mask |= wxLIST_MASK_STATE;
1855
1856 if ( lvItem.stateMask & LVIS_CUT)
1857 {
edccf428 1858 info.m_stateMask |= wxLIST_STATE_CUT;
0b5efdc7 1859 if ( lvItem.state & LVIS_CUT )
edccf428 1860 info.m_state |= wxLIST_STATE_CUT;
0b5efdc7
VZ
1861 }
1862 if ( lvItem.stateMask & LVIS_DROPHILITED)
1863 {
edccf428 1864 info.m_stateMask |= wxLIST_STATE_DROPHILITED;
0b5efdc7 1865 if ( lvItem.state & LVIS_DROPHILITED )
edccf428 1866 info.m_state |= wxLIST_STATE_DROPHILITED;
0b5efdc7
VZ
1867 }
1868 if ( lvItem.stateMask & LVIS_FOCUSED)
1869 {
edccf428 1870 info.m_stateMask |= wxLIST_STATE_FOCUSED;
0b5efdc7 1871 if ( lvItem.state & LVIS_FOCUSED )
edccf428 1872 info.m_state |= wxLIST_STATE_FOCUSED;
0b5efdc7
VZ
1873 }
1874 if ( lvItem.stateMask & LVIS_SELECTED)
1875 {
edccf428 1876 info.m_stateMask |= wxLIST_STATE_SELECTED;
0b5efdc7 1877 if ( lvItem.state & LVIS_SELECTED )
edccf428 1878 info.m_state |= wxLIST_STATE_SELECTED;
0b5efdc7 1879 }
acb62b84 1880 }
0b5efdc7
VZ
1881
1882 if ( lvItem.mask & LVIF_TEXT )
acb62b84 1883 {
0b5efdc7
VZ
1884 info.m_mask |= wxLIST_MASK_TEXT;
1885 info.m_text = lvItem.pszText;
acb62b84 1886 }
0b5efdc7 1887 if ( lvItem.mask & LVIF_IMAGE )
acb62b84 1888 {
0b5efdc7
VZ
1889 info.m_mask |= wxLIST_MASK_IMAGE;
1890 info.m_image = lvItem.iImage;
acb62b84 1891 }
0b5efdc7
VZ
1892 if ( lvItem.mask & LVIF_PARAM )
1893 info.m_mask |= wxLIST_MASK_DATA;
1894 if ( lvItem.mask & LVIF_DI_SETITEM )
1895 info.m_mask |= wxLIST_SET_ITEM;
1896 info.m_col = lvItem.iSubItem;
1897
1898 if (needText)
acb62b84 1899 {
0b5efdc7
VZ
1900 if (lvItem.pszText)
1901 delete[] lvItem.pszText;
acb62b84 1902 }
edccf428 1903 lvItem.mask = oldMask;
2bda0e17
KB
1904}
1905
1906static void wxConvertToMSWListItem(const wxListCtrl *ctrl, wxListItem& info, LV_ITEM& lvItem)
1907{
edccf428 1908 lvItem.iItem = (int) info.m_itemId;
acb62b84 1909
edccf428 1910 lvItem.iImage = info.m_image;
0b5efdc7
VZ
1911 lvItem.lParam = info.m_data;
1912 lvItem.stateMask = 0;
1913 lvItem.state = 0;
1914 lvItem.mask = 0;
1915 lvItem.iSubItem = info.m_col;
acb62b84 1916
0b5efdc7 1917 if (info.m_mask & wxLIST_MASK_STATE)
acb62b84 1918 {
edccf428 1919 lvItem.mask |= LVIF_STATE;
0b5efdc7
VZ
1920 if (info.m_stateMask & wxLIST_STATE_CUT)
1921 {
edccf428 1922 lvItem.stateMask |= LVIS_CUT;
0b5efdc7
VZ
1923 if (info.m_state & wxLIST_STATE_CUT)
1924 lvItem.state |= LVIS_CUT;
1925 }
1926 if (info.m_stateMask & wxLIST_STATE_DROPHILITED)
1927 {
1928 lvItem.stateMask |= LVIS_DROPHILITED;
1929 if (info.m_state & wxLIST_STATE_DROPHILITED)
1930 lvItem.state |= LVIS_DROPHILITED;
1931 }
1932 if (info.m_stateMask & wxLIST_STATE_FOCUSED)
1933 {
1934 lvItem.stateMask |= LVIS_FOCUSED;
1935 if (info.m_state & wxLIST_STATE_FOCUSED)
1936 lvItem.state |= LVIS_FOCUSED;
1937 }
1938 if (info.m_stateMask & wxLIST_STATE_SELECTED)
1939 {
1940 lvItem.stateMask |= LVIS_SELECTED;
1941 if (info.m_state & wxLIST_STATE_SELECTED)
1942 lvItem.state |= LVIS_SELECTED;
1943 }
acb62b84 1944 }
acb62b84 1945
0b5efdc7 1946 if (info.m_mask & wxLIST_MASK_TEXT)
acb62b84 1947 {
edccf428 1948 lvItem.mask |= LVIF_TEXT;
0b5efdc7
VZ
1949 if ( ctrl->GetWindowStyleFlag() & wxLC_USER_TEXT )
1950 {
1951 lvItem.pszText = LPSTR_TEXTCALLBACK;
1952 }
1953 else
1954 {
edccf428 1955 lvItem.pszText = WXSTRINGCAST info.m_text;
0b5efdc7
VZ
1956 if ( lvItem.pszText )
1957 lvItem.cchTextMax = info.m_text.Length();
1958 else
1959 lvItem.cchTextMax = 0;
1960 }
acb62b84 1961 }
0b5efdc7 1962 if (info.m_mask & wxLIST_MASK_IMAGE)
edccf428 1963 lvItem.mask |= LVIF_IMAGE;
0b5efdc7 1964 if (info.m_mask & wxLIST_MASK_DATA)
edccf428 1965 lvItem.mask |= LVIF_PARAM;
2bda0e17
KB
1966}
1967
edccf428 1968// ----------------------------------------------------------------------------
2bda0e17 1969// List event
edccf428
VZ
1970// ----------------------------------------------------------------------------
1971
92976ab6 1972IMPLEMENT_DYNAMIC_CLASS(wxListEvent, wxNotifyEvent)
2bda0e17 1973
fd3f686c 1974wxListEvent::wxListEvent(wxEventType commandType, int id)
edccf428 1975 : wxNotifyEvent(commandType, id)
2bda0e17 1976{
0b5efdc7
VZ
1977 m_code = 0;
1978 m_itemIndex = 0;
5d47c8a0 1979 m_oldItemIndex = 0;
0b5efdc7
VZ
1980 m_col = 0;
1981 m_cancelled = FALSE;
2bda0e17
KB
1982}
1983
edccf428 1984#endif // __WIN95__
2bda0e17 1985