1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/listctrl.cpp
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
33 #include "wx/settings.h"
34 #include "wx/dcclient.h"
37 #include "wx/textctrl.h"
38 #include "wx/imaglist.h"
39 #include "wx/listctrl.h"
41 #include "wx/msw/private.h"
43 #if defined(__WXWINCE__) && !defined(__HANDHELDPC__)
51 // include <commctrl.h> "properly"
52 #include "wx/msw/wrapcctl.h"
54 // Currently gcc and watcom don't define NMLVFINDITEM, and DMC only defines
55 // it by its old name NM_FINDTIEM.
57 #if defined(__VISUALC__) || defined(__BORLANDC__) || defined(NMLVFINDITEM)
58 #define HAVE_NMLVFINDITEM 1
59 #elif defined(__DMC__) || defined(NM_FINDITEM)
60 #define HAVE_NMLVFINDITEM 1
61 #define NMLVFINDITEM NM_FINDITEM
64 // ----------------------------------------------------------------------------
66 // ----------------------------------------------------------------------------
68 // convert our state and mask flags to LV_ITEM constants
69 static void wxConvertToMSWFlags(long state
, long mask
, LV_ITEM
& lvItem
);
71 // convert wxListItem to LV_ITEM
72 static void wxConvertToMSWListItem(const wxListCtrl
*ctrl
,
73 const wxListItem
& info
, LV_ITEM
& lvItem
);
75 // convert LV_ITEM to wxListItem
76 static void wxConvertFromMSWListItem(HWND hwndListCtrl
,
78 /* const */ LV_ITEM
& lvItem
);
80 // convert our wxListItem to LV_COLUMN
81 static void wxConvertToMSWListCol(HWND hwndList
,
83 const wxListItem
& item
,
86 // ----------------------------------------------------------------------------
87 // private helper classes
88 // ----------------------------------------------------------------------------
90 // We have to handle both fooW and fooA notifications in several cases
91 // because of broken comctl32.dll and/or unicows.dll. This class is used to
92 // convert LV_ITEMA and LV_ITEMW to LV_ITEM (which is either LV_ITEMA or
93 // LV_ITEMW depending on wxUSE_UNICODE setting), so that it can be processed
94 // by wxConvertToMSWListItem().
96 #define LV_ITEM_NATIVE LV_ITEMW
97 #define LV_ITEM_OTHER LV_ITEMA
99 #define LV_CONV_TO_WX cMB2WX
100 #define LV_CONV_BUF wxMB2WXbuf
102 #define LV_ITEM_NATIVE LV_ITEMA
103 #define LV_ITEM_OTHER LV_ITEMW
105 #define LV_CONV_TO_WX cWC2WX
106 #define LV_CONV_BUF wxWC2WXbuf
107 #endif // Unicode/ANSI
112 // default ctor, use Init() later
113 wxLV_ITEM() { m_buf
= NULL
; m_pItem
= NULL
; }
115 // init without conversion
116 void Init(LV_ITEM_NATIVE
& item
)
118 wxASSERT_MSG( !m_pItem
, _T("Init() called twice?") );
123 // init with conversion
124 void Init(const LV_ITEM_OTHER
& item
)
126 // avoid unnecessary dynamic memory allocation, jjust make m_pItem
127 // point to our own m_item
129 // memcpy() can't work if the struct sizes are different
130 wxCOMPILE_TIME_ASSERT( sizeof(LV_ITEM_OTHER
) == sizeof(LV_ITEM_NATIVE
),
131 CodeCantWorkIfDiffSizes
);
133 memcpy(&m_item
, &item
, sizeof(LV_ITEM_NATIVE
));
135 // convert text from ANSI to Unicod if necessary
136 if ( (item
.mask
& LVIF_TEXT
) && item
.pszText
)
138 m_buf
= new LV_CONV_BUF(wxConvLocal
.LV_CONV_TO_WX(item
.pszText
));
139 m_item
.pszText
= (wxChar
*)m_buf
->data();
143 // ctor without conversion
144 wxLV_ITEM(LV_ITEM_NATIVE
& item
) : m_buf(NULL
), m_pItem(&item
) { }
146 // ctor with conversion
147 wxLV_ITEM(LV_ITEM_OTHER
& item
) : m_buf(NULL
)
152 ~wxLV_ITEM() { delete m_buf
; }
154 // conversion to the real LV_ITEM
155 operator LV_ITEM_NATIVE
&() const { return *m_pItem
; }
160 LV_ITEM_NATIVE
*m_pItem
;
161 LV_ITEM_NATIVE m_item
;
163 DECLARE_NO_COPY_CLASS(wxLV_ITEM
)
166 ///////////////////////////////////////////////////////
168 // The MSW version had problems with SetTextColour() et
169 // al as the wxListItemAttr's were stored keyed on the
170 // item index. If a item was inserted anywhere but the end
171 // of the list the the text attributes (colour etc) for
172 // the following items were out of sync.
175 // Under MSW the only way to associate data with a List
176 // item independent of its position in the list is to
177 // store a pointer to it in its lParam attribute. However
178 // user programs are already using this (via the
179 // SetItemData() GetItemData() calls).
181 // However what we can do is store a pointer to a
182 // structure which contains the attributes we want *and*
183 // a lParam for the users data, e.g.
185 // class wxListItemInternalData
188 // wxListItemAttr *attr;
189 // long lParam; // user data
192 // To conserve memory, a wxListItemInternalData is
193 // only allocated for a LV_ITEM if text attributes or
194 // user data(lparam) are being set.
197 // class wxListItemInternalData
198 class wxListItemInternalData
201 wxListItemAttr
*attr
;
202 LPARAM lParam
; // user data
204 wxListItemInternalData() : attr(NULL
), lParam(0) {}
205 ~wxListItemInternalData()
211 DECLARE_NO_COPY_CLASS(wxListItemInternalData
)
214 // Get the internal data structure
215 static wxListItemInternalData
*wxGetInternalData(HWND hwnd
, long itemId
);
216 static wxListItemInternalData
*wxGetInternalData(const wxListCtrl
*ctl
, long itemId
);
217 static wxListItemAttr
*wxGetInternalDataAttr(const wxListCtrl
*ctl
, long itemId
);
218 static void wxDeleteInternalData(wxListCtrl
* ctl
, long itemId
);
221 // ----------------------------------------------------------------------------
223 // ----------------------------------------------------------------------------
225 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG
)
226 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG
)
227 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
)
228 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT
)
229 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM
)
230 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
)
231 #if WXWIN_COMPATIBILITY_2_4
232 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO
)
233 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO
)
235 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED
)
236 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED
)
237 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN
)
238 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM
)
239 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK
)
240 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
)
241 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
)
242 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_DRAGGING
)
243 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_END_DRAG
)
244 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
)
245 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
)
246 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED
)
247 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_FOCUSED
)
248 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT
)
250 #if wxUSE_EXTENDED_RTTI
251 WX_DEFINE_FLAGS( wxListCtrlStyle
)
253 wxBEGIN_FLAGS( wxListCtrlStyle
)
254 // new style border flags, we put them first to
255 // use them for streaming out
256 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
257 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
258 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
259 wxFLAGS_MEMBER(wxBORDER_RAISED
)
260 wxFLAGS_MEMBER(wxBORDER_STATIC
)
261 wxFLAGS_MEMBER(wxBORDER_NONE
)
263 // old style border flags
264 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
265 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
266 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
267 wxFLAGS_MEMBER(wxRAISED_BORDER
)
268 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
269 wxFLAGS_MEMBER(wxBORDER
)
271 // standard window styles
272 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
273 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
274 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
275 wxFLAGS_MEMBER(wxWANTS_CHARS
)
276 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
277 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
278 wxFLAGS_MEMBER(wxVSCROLL
)
279 wxFLAGS_MEMBER(wxHSCROLL
)
281 wxFLAGS_MEMBER(wxLC_LIST
)
282 wxFLAGS_MEMBER(wxLC_REPORT
)
283 wxFLAGS_MEMBER(wxLC_ICON
)
284 wxFLAGS_MEMBER(wxLC_SMALL_ICON
)
285 wxFLAGS_MEMBER(wxLC_ALIGN_TOP
)
286 wxFLAGS_MEMBER(wxLC_ALIGN_LEFT
)
287 wxFLAGS_MEMBER(wxLC_AUTOARRANGE
)
288 wxFLAGS_MEMBER(wxLC_USER_TEXT
)
289 wxFLAGS_MEMBER(wxLC_EDIT_LABELS
)
290 wxFLAGS_MEMBER(wxLC_NO_HEADER
)
291 wxFLAGS_MEMBER(wxLC_SINGLE_SEL
)
292 wxFLAGS_MEMBER(wxLC_SORT_ASCENDING
)
293 wxFLAGS_MEMBER(wxLC_SORT_DESCENDING
)
294 wxFLAGS_MEMBER(wxLC_VIRTUAL
)
296 wxEND_FLAGS( wxListCtrlStyle
)
298 IMPLEMENT_DYNAMIC_CLASS_XTI(wxListCtrl
, wxControl
,"wx/listctrl.h")
300 wxBEGIN_PROPERTIES_TABLE(wxListCtrl
)
301 wxEVENT_PROPERTY( TextUpdated
, wxEVT_COMMAND_TEXT_UPDATED
, wxCommandEvent
)
303 wxPROPERTY_FLAGS( WindowStyle
, wxListCtrlStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
304 wxEND_PROPERTIES_TABLE()
306 wxBEGIN_HANDLERS_TABLE(wxListCtrl
)
307 wxEND_HANDLERS_TABLE()
309 wxCONSTRUCTOR_5( wxListCtrl
, wxWindow
* , Parent
, wxWindowID
, Id
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
312 TODO : Expose more information of a list's layout etc. via appropriate objects (Ã la NotebookPageInfo)
315 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
318 IMPLEMENT_DYNAMIC_CLASS(wxListView
, wxListCtrl
)
319 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
321 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
323 BEGIN_EVENT_TABLE(wxListCtrl
, wxControl
)
324 EVT_PAINT(wxListCtrl::OnPaint
)
327 // ============================================================================
329 // ============================================================================
331 // ----------------------------------------------------------------------------
332 // wxListCtrl construction
333 // ----------------------------------------------------------------------------
335 void wxListCtrl::Init()
337 m_imageListNormal
= NULL
;
338 m_imageListSmall
= NULL
;
339 m_imageListState
= NULL
;
340 m_ownsImageListNormal
= m_ownsImageListSmall
= m_ownsImageListState
= false;
343 m_ignoreChangeMessages
= false;
345 m_AnyInternalData
= false;
346 m_hasAnyAttr
= false;
349 bool wxListCtrl::Create(wxWindow
*parent
,
354 const wxValidator
& validator
,
355 const wxString
& name
)
357 if ( !CreateControl(parent
, id
, pos
, size
, style
, validator
, name
) )
360 if ( !MSWCreateControl(WC_LISTVIEW
, wxEmptyString
, pos
, size
) )
363 // explicitly say that we want to use Unicode because otherwise we get ANSI
364 // versions of _some_ messages (notably LVN_GETDISPINFOA) in MSLU build
365 wxSetCCUnicodeFormat(GetHwnd());
367 // We must set the default text colour to the system/theme color, otherwise
368 // GetTextColour will always return black
369 SetTextColour(GetDefaultAttributes().colFg
);
371 // for comctl32.dll v 4.70+ we want to have some non default extended
372 // styles because it's prettier (and also because wxGTK does it like this)
373 if ( InReportView() && wxApp::GetComCtl32Version() >= 470 )
375 ::SendMessage(GetHwnd(), LVM_SETEXTENDEDLISTVIEWSTYLE
,
376 0, LVS_EX_LABELTIP
| LVS_EX_FULLROWSELECT
| LVS_EX_SUBITEMIMAGES
);
382 WXDWORD
wxListCtrl::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
384 WXDWORD wstyle
= wxControl::MSWGetStyle(style
, exstyle
);
386 wstyle
|= LVS_SHAREIMAGELISTS
| LVS_SHOWSELALWAYS
;
391 #define MAP_MODE_STYLE(wx, ms) \
392 if ( style & (wx) ) { wstyle |= (ms); nModes++; }
393 #else // !__WXDEBUG__
394 #define MAP_MODE_STYLE(wx, ms) \
395 if ( style & (wx) ) wstyle |= (ms);
396 #endif // __WXDEBUG__
398 MAP_MODE_STYLE(wxLC_ICON
, LVS_ICON
)
399 MAP_MODE_STYLE(wxLC_SMALL_ICON
, LVS_SMALLICON
)
400 MAP_MODE_STYLE(wxLC_LIST
, LVS_LIST
)
401 MAP_MODE_STYLE(wxLC_REPORT
, LVS_REPORT
)
403 wxASSERT_MSG( nModes
== 1,
404 _T("wxListCtrl style should have exactly one mode bit set") );
406 #undef MAP_MODE_STYLE
408 if ( style
& wxLC_ALIGN_LEFT
)
409 wstyle
|= LVS_ALIGNLEFT
;
411 if ( style
& wxLC_ALIGN_TOP
)
412 wstyle
|= LVS_ALIGNTOP
;
414 if ( style
& wxLC_AUTOARRANGE
)
415 wstyle
|= LVS_AUTOARRANGE
;
417 if ( style
& wxLC_NO_SORT_HEADER
)
418 wstyle
|= LVS_NOSORTHEADER
;
420 if ( style
& wxLC_NO_HEADER
)
421 wstyle
|= LVS_NOCOLUMNHEADER
;
423 if ( style
& wxLC_EDIT_LABELS
)
424 wstyle
|= LVS_EDITLABELS
;
426 if ( style
& wxLC_SINGLE_SEL
)
427 wstyle
|= LVS_SINGLESEL
;
429 if ( style
& wxLC_SORT_ASCENDING
)
431 wstyle
|= LVS_SORTASCENDING
;
433 wxASSERT_MSG( !(style
& wxLC_SORT_DESCENDING
),
434 _T("can't sort in ascending and descending orders at once") );
436 else if ( style
& wxLC_SORT_DESCENDING
)
437 wstyle
|= LVS_SORTDESCENDING
;
439 #if !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 0 ) )
440 if ( style
& wxLC_VIRTUAL
)
442 int ver
= wxApp::GetComCtl32Version();
445 wxLogWarning(_("Please install a newer version of comctl32.dll\n(at least version 4.70 is required but you have %d.%02d)\nor this program won't operate correctly."),
446 ver
/ 100, ver
% 100);
449 wstyle
|= LVS_OWNERDATA
;
451 #endif // ancient cygwin
456 void wxListCtrl::UpdateStyle()
460 // The new window view style
461 DWORD dwStyleNew
= MSWGetStyle(m_windowStyle
, NULL
);
463 // some styles are not returned by MSWGetStyle()
465 dwStyleNew
|= WS_VISIBLE
;
467 // Get the current window style.
468 DWORD dwStyleOld
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
470 // we don't have wxVSCROLL style, but the list control may have it,
471 // don't change it then
472 dwStyleNew
|= dwStyleOld
& (WS_HSCROLL
| WS_VSCROLL
);
474 // Only set the window style if the view bits have changed.
475 if ( dwStyleOld
!= dwStyleNew
)
477 ::SetWindowLong(GetHwnd(), GWL_STYLE
, dwStyleNew
);
482 void wxListCtrl::FreeAllInternalData()
484 if (m_AnyInternalData
)
486 int n
= GetItemCount();
488 m_ignoreChangeMessages
= true;
489 for (int i
= 0; i
< n
; i
++)
490 wxDeleteInternalData(this, i
);
491 m_ignoreChangeMessages
= false;
493 m_AnyInternalData
= false;
497 wxListCtrl::~wxListCtrl()
499 FreeAllInternalData();
503 m_textCtrl
->UnsubclassWin();
504 m_textCtrl
->SetHWND(0);
509 if (m_ownsImageListNormal
)
510 delete m_imageListNormal
;
511 if (m_ownsImageListSmall
)
512 delete m_imageListSmall
;
513 if (m_ownsImageListState
)
514 delete m_imageListState
;
517 // ----------------------------------------------------------------------------
518 // set/get/change style
519 // ----------------------------------------------------------------------------
521 // Add or remove a single window style
522 void wxListCtrl::SetSingleStyle(long style
, bool add
)
524 long flag
= GetWindowStyleFlag();
526 // Get rid of conflicting styles
529 if ( style
& wxLC_MASK_TYPE
)
530 flag
= flag
& ~wxLC_MASK_TYPE
;
531 if ( style
& wxLC_MASK_ALIGN
)
532 flag
= flag
& ~wxLC_MASK_ALIGN
;
533 if ( style
& wxLC_MASK_SORT
)
534 flag
= flag
& ~wxLC_MASK_SORT
;
542 SetWindowStyleFlag(flag
);
545 // Set the whole window style
546 void wxListCtrl::SetWindowStyleFlag(long flag
)
548 if ( flag
!= m_windowStyle
)
550 m_windowStyle
= flag
;
558 // ----------------------------------------------------------------------------
560 // ----------------------------------------------------------------------------
562 /* static */ wxVisualAttributes
563 wxListCtrl::GetClassDefaultAttributes(wxWindowVariant variant
)
565 wxVisualAttributes attrs
= GetCompositeControlsDefaultAttributes(variant
);
567 // common controls have their own default font
568 attrs
.font
= wxGetCCDefaultFont();
573 // Sets the foreground, i.e. text, colour
574 bool wxListCtrl::SetForegroundColour(const wxColour
& col
)
576 if ( !wxWindow::SetForegroundColour(col
) )
579 ListView_SetTextColor(GetHwnd(), wxColourToRGB(col
));
584 // Sets the background colour
585 bool wxListCtrl::SetBackgroundColour(const wxColour
& col
)
587 if ( !wxWindow::SetBackgroundColour(col
) )
590 // we set the same colour for both the "empty" background and the items
592 COLORREF color
= wxColourToRGB(col
);
593 ListView_SetBkColor(GetHwnd(), color
);
594 ListView_SetTextBkColor(GetHwnd(), color
);
599 // Gets information about this column
600 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
605 lvCol
.mask
= LVCF_WIDTH
;
607 if ( item
.m_mask
& wxLIST_MASK_TEXT
)
609 lvCol
.mask
|= LVCF_TEXT
;
610 lvCol
.pszText
= new wxChar
[513];
611 lvCol
.cchTextMax
= 512;
614 if ( item
.m_mask
& wxLIST_MASK_FORMAT
)
616 lvCol
.mask
|= LVCF_FMT
;
619 if ( item
.m_mask
& wxLIST_MASK_IMAGE
)
621 lvCol
.mask
|= LVCF_IMAGE
;
624 bool success
= ListView_GetColumn(GetHwnd(), col
, &lvCol
) != 0;
626 // item.m_subItem = lvCol.iSubItem;
627 item
.m_width
= lvCol
.cx
;
629 if ( (item
.m_mask
& wxLIST_MASK_TEXT
) && lvCol
.pszText
)
631 item
.m_text
= lvCol
.pszText
;
632 delete[] lvCol
.pszText
;
635 if ( item
.m_mask
& wxLIST_MASK_FORMAT
)
637 switch (lvCol
.fmt
& LVCFMT_JUSTIFYMASK
) {
639 item
.m_format
= wxLIST_FORMAT_LEFT
;
642 item
.m_format
= wxLIST_FORMAT_RIGHT
;
645 item
.m_format
= wxLIST_FORMAT_CENTRE
;
648 item
.m_format
= -1; // Unknown?
653 // the column images were not supported in older versions but how to check
654 // for this? we can't use _WIN32_IE because we always define it to a very
655 // high value, so see if another symbol which is only defined starting from
656 // comctl32.dll 4.70 is available
657 #ifdef NM_CUSTOMDRAW // _WIN32_IE >= 0x0300
658 if ( item
.m_mask
& wxLIST_MASK_IMAGE
)
660 item
.m_image
= lvCol
.iImage
;
662 #endif // LVCOLUMN::iImage exists
667 // Sets information about this column
668 bool wxListCtrl::SetColumn(int col
, const wxListItem
& item
)
671 wxConvertToMSWListCol(GetHwnd(), col
, item
, lvCol
);
673 return ListView_SetColumn(GetHwnd(), col
, &lvCol
) != 0;
676 // Gets the column width
677 int wxListCtrl::GetColumnWidth(int col
) const
679 return ListView_GetColumnWidth(GetHwnd(), col
);
682 // Sets the column width
683 bool wxListCtrl::SetColumnWidth(int col
, int width
)
685 if ( m_windowStyle
& wxLC_LIST
)
688 if ( width
== wxLIST_AUTOSIZE
)
689 width
= LVSCW_AUTOSIZE
;
690 else if ( width
== wxLIST_AUTOSIZE_USEHEADER
)
691 width
= LVSCW_AUTOSIZE_USEHEADER
;
693 return ListView_SetColumnWidth(GetHwnd(), col
, width
) != 0;
696 // Gets the number of items that can fit vertically in the
697 // visible area of the list control (list or report view)
698 // or the total number of items in the list control (icon
699 // or small icon view)
700 int wxListCtrl::GetCountPerPage() const
702 return ListView_GetCountPerPage(GetHwnd());
705 // Gets the edit control for editing labels.
706 wxTextCtrl
* wxListCtrl::GetEditControl() const
711 // Gets information about the item
712 bool wxListCtrl::GetItem(wxListItem
& info
) const
715 wxZeroMemory(lvItem
);
717 lvItem
.iItem
= info
.m_itemId
;
718 lvItem
.iSubItem
= info
.m_col
;
720 if ( info
.m_mask
& wxLIST_MASK_TEXT
)
722 lvItem
.mask
|= LVIF_TEXT
;
723 lvItem
.pszText
= new wxChar
[513];
724 lvItem
.cchTextMax
= 512;
728 lvItem
.pszText
= NULL
;
731 if (info
.m_mask
& wxLIST_MASK_DATA
)
732 lvItem
.mask
|= LVIF_PARAM
;
734 if (info
.m_mask
& wxLIST_MASK_IMAGE
)
735 lvItem
.mask
|= LVIF_IMAGE
;
737 if ( info
.m_mask
& wxLIST_MASK_STATE
)
739 lvItem
.mask
|= LVIF_STATE
;
740 wxConvertToMSWFlags(0, info
.m_stateMask
, lvItem
);
743 bool success
= ListView_GetItem((HWND
)GetHWND(), &lvItem
) != 0;
746 wxLogError(_("Couldn't retrieve information about list control item %d."),
751 // give NULL as hwnd as we already have everything we need
752 wxConvertFromMSWListItem(NULL
, info
, lvItem
);
756 delete[] lvItem
.pszText
;
761 // Sets information about the item
762 bool wxListCtrl::SetItem(wxListItem
& info
)
764 const long id
= info
.GetId();
765 wxCHECK_MSG( id
>= 0 && id
< GetItemCount(), false,
766 _T("invalid item index in SetItem") );
769 wxConvertToMSWListItem(this, info
, item
);
771 // we never update the lParam if it contains our pointer
772 // to the wxListItemInternalData structure
773 item
.mask
&= ~LVIF_PARAM
;
775 // check if setting attributes or lParam
776 if (info
.HasAttributes() || (info
.m_mask
& wxLIST_MASK_DATA
))
778 // get internal item data
779 // perhaps a cache here ?
780 wxListItemInternalData
*data
= wxGetInternalData(this, id
);
785 m_AnyInternalData
= true;
786 data
= new wxListItemInternalData();
787 item
.lParam
= (LPARAM
) data
;
788 item
.mask
|= LVIF_PARAM
;
793 if (info
.m_mask
& wxLIST_MASK_DATA
)
794 data
->lParam
= info
.m_data
;
797 if ( info
.HasAttributes() )
799 const wxListItemAttr
& attrNew
= *info
.GetAttributes();
801 // don't overwrite the already set attributes if we have them
803 data
->attr
->AssignFrom(attrNew
);
805 data
->attr
= new wxListItemAttr(attrNew
);
810 // we could be changing only the attribute in which case we don't need to
811 // call ListView_SetItem() at all
815 if ( !ListView_SetItem(GetHwnd(), &item
) )
817 wxLogDebug(_T("ListView_SetItem() failed"));
823 // we need to update the item immediately to show the new image
824 bool updateNow
= (info
.m_mask
& wxLIST_MASK_IMAGE
) != 0;
826 // check whether it has any custom attributes
827 if ( info
.HasAttributes() )
831 // if the colour has changed, we must redraw the item
837 // we need this to make the change visible right now
838 RefreshItem(item
.iItem
);
844 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
848 info
.m_mask
= wxLIST_MASK_TEXT
;
849 info
.m_itemId
= index
;
853 info
.m_image
= imageId
;
854 info
.m_mask
|= wxLIST_MASK_IMAGE
;
856 return SetItem(info
);
860 // Gets the item state
861 int wxListCtrl::GetItemState(long item
, long stateMask
) const
865 info
.m_mask
= wxLIST_MASK_STATE
;
866 info
.m_stateMask
= stateMask
;
867 info
.m_itemId
= item
;
875 // Sets the item state
876 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
878 // NB: don't use SetItem() here as it doesn't work with the virtual list
881 wxZeroMemory(lvItem
);
883 wxConvertToMSWFlags(state
, stateMask
, lvItem
);
885 // for the virtual list controls we need to refresh the previously focused
886 // item manually when changing focus without changing selection
887 // programmatically because otherwise it keeps its focus rectangle until
888 // next repaint (yet another comctl32 bug)
891 (stateMask
& wxLIST_STATE_FOCUSED
) &&
892 (state
& wxLIST_STATE_FOCUSED
) )
894 focusOld
= GetNextItem(-1, wxLIST_NEXT_ALL
, wxLIST_STATE_FOCUSED
);
901 if ( !::SendMessage(GetHwnd(), LVM_SETITEMSTATE
,
902 (WPARAM
)item
, (LPARAM
)&lvItem
) )
904 wxLogLastError(_T("ListView_SetItemState"));
909 if ( focusOld
!= -1 )
911 // no need to refresh the item if it was previously selected, it would
912 // only result in annoying flicker
913 if ( !(GetItemState(focusOld
,
914 wxLIST_STATE_SELECTED
) & wxLIST_STATE_SELECTED
) )
916 RefreshItem(focusOld
);
923 // Sets the item image
924 bool wxListCtrl::SetItemImage(long item
, int image
, int WXUNUSED(selImage
))
926 return SetItemColumnImage(item
, 0, image
);
929 // Sets the item image
930 bool wxListCtrl::SetItemColumnImage(long item
, long column
, int image
)
934 info
.m_mask
= wxLIST_MASK_IMAGE
;
935 info
.m_image
= image
;
936 info
.m_itemId
= item
;
939 return SetItem(info
);
942 // Gets the item text
943 wxString
wxListCtrl::GetItemText(long item
) const
947 info
.m_mask
= wxLIST_MASK_TEXT
;
948 info
.m_itemId
= item
;
951 return wxEmptyString
;
955 // Sets the item text
956 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
960 info
.m_mask
= wxLIST_MASK_TEXT
;
961 info
.m_itemId
= item
;
967 // Gets the item data
968 wxUIntPtr
wxListCtrl::GetItemData(long item
) const
972 info
.m_mask
= wxLIST_MASK_DATA
;
973 info
.m_itemId
= item
;
980 // Sets the item data
981 bool wxListCtrl::SetItemData(long item
, long data
)
985 info
.m_mask
= wxLIST_MASK_DATA
;
986 info
.m_itemId
= item
;
989 return SetItem(info
);
992 wxRect
wxListCtrl::GetViewRect() const
994 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
995 _T("wxListCtrl::GetViewRect() only works in icon mode") );
998 if ( !ListView_GetViewRect(GetHwnd(), &rc
) )
1000 wxLogDebug(_T("ListView_GetViewRect() failed."));
1006 wxCopyRECTToRect(rc
, rect
);
1011 // Gets the item rectangle
1012 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
1017 if ( code
== wxLIST_RECT_BOUNDS
)
1018 codeWin
= LVIR_BOUNDS
;
1019 else if ( code
== wxLIST_RECT_ICON
)
1020 codeWin
= LVIR_ICON
;
1021 else if ( code
== wxLIST_RECT_LABEL
)
1022 codeWin
= LVIR_LABEL
;
1025 wxFAIL_MSG( _T("incorrect code in GetItemRect()") );
1027 codeWin
= LVIR_BOUNDS
;
1030 bool success
= ListView_GetItemRect(GetHwnd(), (int) item
, &rectWin
, codeWin
) != 0;
1032 rect
.x
= rectWin
.left
;
1033 rect
.y
= rectWin
.top
;
1034 rect
.width
= rectWin
.right
- rectWin
.left
;
1035 rect
.height
= rectWin
.bottom
- rectWin
.top
;
1040 // Gets the item position
1041 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
1045 bool success
= (ListView_GetItemPosition(GetHwnd(), (int) item
, &pt
) != 0);
1047 pos
.x
= pt
.x
; pos
.y
= pt
.y
;
1051 // Sets the item position.
1052 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
1054 return (ListView_SetItemPosition(GetHwnd(), (int) item
, pos
.x
, pos
.y
) != 0);
1057 // Gets the number of items in the list control
1058 int wxListCtrl::GetItemCount() const
1063 wxSize
wxListCtrl::GetItemSpacing() const
1065 const int spacing
= ListView_GetItemSpacing(GetHwnd(), (BOOL
)HasFlag(wxLC_SMALL_ICON
));
1067 return wxSize(LOWORD(spacing
), HIWORD(spacing
));
1070 #if WXWIN_COMPATIBILITY_2_6
1072 int wxListCtrl::GetItemSpacing(bool isSmall
) const
1074 return ListView_GetItemSpacing(GetHwnd(), (BOOL
) isSmall
);
1077 #endif // WXWIN_COMPATIBILITY_2_6
1079 void wxListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
1082 info
.m_itemId
= item
;
1083 info
.SetTextColour( col
);
1087 wxColour
wxListCtrl::GetItemTextColour( long item
) const
1090 wxListItemInternalData
*data
= wxGetInternalData(this, item
);
1091 if ( data
&& data
->attr
)
1092 col
= data
->attr
->GetTextColour();
1097 void wxListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
1100 info
.m_itemId
= item
;
1101 info
.SetBackgroundColour( col
);
1105 wxColour
wxListCtrl::GetItemBackgroundColour( long item
) const
1108 wxListItemInternalData
*data
= wxGetInternalData(this, item
);
1109 if ( data
&& data
->attr
)
1110 col
= data
->attr
->GetBackgroundColour();
1115 void wxListCtrl::SetItemFont( long item
, const wxFont
&f
)
1118 info
.m_itemId
= item
;
1123 wxFont
wxListCtrl::GetItemFont( long item
) const
1126 wxListItemInternalData
*data
= wxGetInternalData(this, item
);
1127 if ( data
&& data
->attr
)
1128 f
= data
->attr
->GetFont();
1133 // Gets the number of selected items in the list control
1134 int wxListCtrl::GetSelectedItemCount() const
1136 return ListView_GetSelectedCount(GetHwnd());
1139 // Gets the text colour of the listview
1140 wxColour
wxListCtrl::GetTextColour() const
1142 COLORREF ref
= ListView_GetTextColor(GetHwnd());
1143 wxColour
col(GetRValue(ref
), GetGValue(ref
), GetBValue(ref
));
1147 // Sets the text colour of the listview
1148 void wxListCtrl::SetTextColour(const wxColour
& col
)
1150 ListView_SetTextColor(GetHwnd(), PALETTERGB(col
.Red(), col
.Green(), col
.Blue()));
1153 // Gets the index of the topmost visible item when in
1154 // list or report view
1155 long wxListCtrl::GetTopItem() const
1157 return (long) ListView_GetTopIndex(GetHwnd());
1160 // Searches for an item, starting from 'item'.
1161 // 'geometry' is one of
1162 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
1163 // 'state' is a state bit flag, one or more of
1164 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
1165 // item can be -1 to find the first item that matches the
1167 // Returns the item or -1 if unsuccessful.
1168 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
1172 if ( geom
== wxLIST_NEXT_ABOVE
)
1173 flags
|= LVNI_ABOVE
;
1174 if ( geom
== wxLIST_NEXT_ALL
)
1176 if ( geom
== wxLIST_NEXT_BELOW
)
1177 flags
|= LVNI_BELOW
;
1178 if ( geom
== wxLIST_NEXT_LEFT
)
1179 flags
|= LVNI_TOLEFT
;
1180 if ( geom
== wxLIST_NEXT_RIGHT
)
1181 flags
|= LVNI_TORIGHT
;
1183 if ( state
& wxLIST_STATE_CUT
)
1185 if ( state
& wxLIST_STATE_DROPHILITED
)
1186 flags
|= LVNI_DROPHILITED
;
1187 if ( state
& wxLIST_STATE_FOCUSED
)
1188 flags
|= LVNI_FOCUSED
;
1189 if ( state
& wxLIST_STATE_SELECTED
)
1190 flags
|= LVNI_SELECTED
;
1192 return (long) ListView_GetNextItem(GetHwnd(), item
, flags
);
1196 wxImageList
*wxListCtrl::GetImageList(int which
) const
1198 if ( which
== wxIMAGE_LIST_NORMAL
)
1200 return m_imageListNormal
;
1202 else if ( which
== wxIMAGE_LIST_SMALL
)
1204 return m_imageListSmall
;
1206 else if ( which
== wxIMAGE_LIST_STATE
)
1208 return m_imageListState
;
1213 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
1216 if ( which
== wxIMAGE_LIST_NORMAL
)
1218 flags
= LVSIL_NORMAL
;
1219 if (m_ownsImageListNormal
) delete m_imageListNormal
;
1220 m_imageListNormal
= imageList
;
1221 m_ownsImageListNormal
= false;
1223 else if ( which
== wxIMAGE_LIST_SMALL
)
1225 flags
= LVSIL_SMALL
;
1226 if (m_ownsImageListSmall
) delete m_imageListSmall
;
1227 m_imageListSmall
= imageList
;
1228 m_ownsImageListSmall
= false;
1230 else if ( which
== wxIMAGE_LIST_STATE
)
1232 flags
= LVSIL_STATE
;
1233 if (m_ownsImageListState
) delete m_imageListState
;
1234 m_imageListState
= imageList
;
1235 m_ownsImageListState
= false;
1237 (void) ListView_SetImageList(GetHwnd(), (HIMAGELIST
) imageList
? imageList
->GetHIMAGELIST() : 0, flags
);
1240 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
1242 SetImageList(imageList
, which
);
1243 if ( which
== wxIMAGE_LIST_NORMAL
)
1244 m_ownsImageListNormal
= true;
1245 else if ( which
== wxIMAGE_LIST_SMALL
)
1246 m_ownsImageListSmall
= true;
1247 else if ( which
== wxIMAGE_LIST_STATE
)
1248 m_ownsImageListState
= true;
1251 // ----------------------------------------------------------------------------
1253 // ----------------------------------------------------------------------------
1255 // Arranges the items
1256 bool wxListCtrl::Arrange(int flag
)
1259 if ( flag
== wxLIST_ALIGN_LEFT
)
1260 code
= LVA_ALIGNLEFT
;
1261 else if ( flag
== wxLIST_ALIGN_TOP
)
1262 code
= LVA_ALIGNTOP
;
1263 else if ( flag
== wxLIST_ALIGN_DEFAULT
)
1265 else if ( flag
== wxLIST_ALIGN_SNAP_TO_GRID
)
1266 code
= LVA_SNAPTOGRID
;
1268 return (ListView_Arrange(GetHwnd(), code
) != 0);
1272 bool wxListCtrl::DeleteItem(long item
)
1274 if ( !ListView_DeleteItem(GetHwnd(), (int) item
) )
1276 wxLogLastError(_T("ListView_DeleteItem"));
1281 wxASSERT_MSG( m_count
== ListView_GetItemCount(GetHwnd()),
1282 wxT("m_count should match ListView_GetItemCount"));
1284 // the virtual list control doesn't refresh itself correctly, help it
1287 // we need to refresh all the lines below the one which was deleted
1289 if ( item
> 0 && GetItemCount() )
1291 GetItemRect(item
- 1, rectItem
);
1296 rectItem
.height
= 0;
1299 wxRect rectWin
= GetRect();
1300 rectWin
.height
= rectWin
.GetBottom() - rectItem
.GetBottom();
1301 rectWin
.y
= rectItem
.GetBottom();
1303 RefreshRect(rectWin
);
1309 // Deletes all items
1310 bool wxListCtrl::DeleteAllItems()
1312 return ListView_DeleteAllItems(GetHwnd()) != 0;
1315 // Deletes all items
1316 bool wxListCtrl::DeleteAllColumns()
1318 while ( m_colCount
> 0 )
1320 if ( ListView_DeleteColumn(GetHwnd(), 0) == 0 )
1322 wxLogLastError(wxT("ListView_DeleteColumn"));
1330 wxASSERT_MSG( m_colCount
== 0, wxT("no columns should be left") );
1336 bool wxListCtrl::DeleteColumn(int col
)
1338 bool success
= (ListView_DeleteColumn(GetHwnd(), col
) != 0);
1340 if ( success
&& (m_colCount
> 0) )
1345 // Clears items, and columns if there are any.
1346 void wxListCtrl::ClearAll()
1349 if ( m_colCount
> 0 )
1353 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
1355 wxASSERT( (textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
))) );
1357 // ListView_EditLabel requires that the list has focus.
1360 WXHWND hWnd
= (WXHWND
) ListView_EditLabel(GetHwnd(), item
);
1363 // failed to start editing
1367 // [re]create the text control wrapping the HWND we got
1370 m_textCtrl
->UnsubclassWin();
1371 m_textCtrl
->SetHWND(0);
1375 m_textCtrl
= (wxTextCtrl
*)textControlClass
->CreateObject();
1376 m_textCtrl
->SetHWND(hWnd
);
1377 m_textCtrl
->SubclassWin(hWnd
);
1378 m_textCtrl
->SetParent(this);
1380 // we must disallow TABbing away from the control while the edit contol is
1381 // shown because this leaves it in some strange state (just try removing
1382 // this line and then pressing TAB while editing an item in listctrl
1384 m_textCtrl
->SetWindowStyle(m_textCtrl
->GetWindowStyle() | wxTE_PROCESS_TAB
);
1389 // End label editing, optionally cancelling the edit
1390 bool wxListCtrl::EndEditLabel(bool cancel
)
1392 // m_textCtrl is not always ready, ie. in EVT_LIST_BEGIN_LABEL_EDIT
1393 HWND hwnd
= ListView_GetEditControl(GetHwnd());
1394 bool b
= (hwnd
!= NULL
);
1398 ::SetWindowText(hwnd
, wxEmptyString
); // dubious but better than nothing
1401 m_textCtrl
->UnsubclassWin();
1402 m_textCtrl
->SetHWND(0);
1406 ::DestroyWindow(hwnd
);
1411 // Ensures this item is visible
1412 bool wxListCtrl::EnsureVisible(long item
)
1414 return ListView_EnsureVisible(GetHwnd(), (int) item
, FALSE
) != FALSE
;
1417 // Find an item whose label matches this string, starting from the item after 'start'
1418 // or the beginning if 'start' is -1.
1419 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
1421 LV_FINDINFO findInfo
;
1423 findInfo
.flags
= LVFI_STRING
;
1425 findInfo
.flags
|= LVFI_PARTIAL
;
1428 // ListView_FindItem() excludes the first item from search and to look
1429 // through all the items you need to start from -1 which is unnatural and
1430 // inconsistent with the generic version - so we adjust the index
1433 return ListView_FindItem(GetHwnd(), (int) start
, &findInfo
);
1436 // Find an item whose data matches this data, starting from the item after 'start'
1437 // or the beginning if 'start' is -1.
1438 // NOTE : Lindsay Mathieson - 14-July-2002
1439 // No longer use ListView_FindItem as the data attribute is now stored
1440 // in a wxListItemInternalData structure refernced by the actual lParam
1441 long wxListCtrl::FindItem(long start
, wxUIntPtr data
)
1443 long idx
= start
+ 1;
1444 long count
= GetItemCount();
1448 if (GetItemData(idx
) == data
)
1456 // Find an item nearest this position in the specified direction, starting from
1457 // the item after 'start' or the beginning if 'start' is -1.
1458 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
1460 LV_FINDINFO findInfo
;
1462 findInfo
.flags
= LVFI_NEARESTXY
;
1463 findInfo
.pt
.x
= pt
.x
;
1464 findInfo
.pt
.y
= pt
.y
;
1465 findInfo
.vkDirection
= VK_RIGHT
;
1467 if ( direction
== wxLIST_FIND_UP
)
1468 findInfo
.vkDirection
= VK_UP
;
1469 else if ( direction
== wxLIST_FIND_DOWN
)
1470 findInfo
.vkDirection
= VK_DOWN
;
1471 else if ( direction
== wxLIST_FIND_LEFT
)
1472 findInfo
.vkDirection
= VK_LEFT
;
1473 else if ( direction
== wxLIST_FIND_RIGHT
)
1474 findInfo
.vkDirection
= VK_RIGHT
;
1476 return ListView_FindItem(GetHwnd(), (int) start
, & findInfo
);
1479 // Determines which item (if any) is at the specified point,
1480 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1481 long wxListCtrl::HitTest(const wxPoint
& point
, int& flags
)
1483 LV_HITTESTINFO hitTestInfo
;
1484 hitTestInfo
.pt
.x
= (int) point
.x
;
1485 hitTestInfo
.pt
.y
= (int) point
.y
;
1487 ListView_HitTest(GetHwnd(), & hitTestInfo
);
1491 if ( hitTestInfo
.flags
& LVHT_ABOVE
)
1492 flags
|= wxLIST_HITTEST_ABOVE
;
1493 if ( hitTestInfo
.flags
& LVHT_BELOW
)
1494 flags
|= wxLIST_HITTEST_BELOW
;
1495 if ( hitTestInfo
.flags
& LVHT_TOLEFT
)
1496 flags
|= wxLIST_HITTEST_TOLEFT
;
1497 if ( hitTestInfo
.flags
& LVHT_TORIGHT
)
1498 flags
|= wxLIST_HITTEST_TORIGHT
;
1500 if ( hitTestInfo
.flags
& LVHT_NOWHERE
)
1501 flags
|= wxLIST_HITTEST_NOWHERE
;
1503 // note a bug or at least a very strange feature of comtl32.dll (tested
1504 // with version 4.0 under Win95 and 6.0 under Win 2003): if you click to
1505 // the right of the item label, ListView_HitTest() returns a combination of
1506 // LVHT_ONITEMICON, LVHT_ONITEMLABEL and LVHT_ONITEMSTATEICON -- filter out
1507 // the bits which don't make sense
1508 if ( hitTestInfo
.flags
& LVHT_ONITEMLABEL
)
1510 flags
|= wxLIST_HITTEST_ONITEMLABEL
;
1512 // do not translate LVHT_ONITEMICON here, as per above
1516 if ( hitTestInfo
.flags
& LVHT_ONITEMICON
)
1517 flags
|= wxLIST_HITTEST_ONITEMICON
;
1518 if ( hitTestInfo
.flags
& LVHT_ONITEMSTATEICON
)
1519 flags
|= wxLIST_HITTEST_ONITEMSTATEICON
;
1522 return (long) hitTestInfo
.iItem
;
1525 // Inserts an item, returning the index of the new item if successful,
1527 long wxListCtrl::InsertItem(const wxListItem
& info
)
1529 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") );
1532 wxConvertToMSWListItem(this, info
, item
);
1533 item
.mask
&= ~LVIF_PARAM
;
1535 // check wether we need to allocate our internal data
1536 bool needInternalData
= ((info
.m_mask
& wxLIST_MASK_DATA
) || info
.HasAttributes());
1537 if (needInternalData
)
1539 m_AnyInternalData
= true;
1540 item
.mask
|= LVIF_PARAM
;
1542 // internal stucture that manages data
1543 wxListItemInternalData
*data
= new wxListItemInternalData();
1544 item
.lParam
= (LPARAM
) data
;
1546 if (info
.m_mask
& wxLIST_MASK_DATA
)
1547 data
->lParam
= info
.m_data
;
1549 // check whether it has any custom attributes
1550 if ( info
.HasAttributes() )
1552 // take copy of attributes
1553 data
->attr
= new wxListItemAttr(*info
.GetAttributes());
1555 // and remember that we have some now...
1556 m_hasAnyAttr
= true;
1560 long rv
= ListView_InsertItem(GetHwnd(), & item
);
1563 wxASSERT_MSG( m_count
== ListView_GetItemCount(GetHwnd()),
1564 wxT("m_count should match ListView_GetItemCount"));
1569 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
1572 info
.m_text
= label
;
1573 info
.m_mask
= wxLIST_MASK_TEXT
;
1574 info
.m_itemId
= index
;
1575 return InsertItem(info
);
1578 // Inserts an image item
1579 long wxListCtrl::InsertItem(long index
, int imageIndex
)
1582 info
.m_image
= imageIndex
;
1583 info
.m_mask
= wxLIST_MASK_IMAGE
;
1584 info
.m_itemId
= index
;
1585 return InsertItem(info
);
1588 // Inserts an image/string item
1589 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
1592 info
.m_image
= imageIndex
;
1593 info
.m_text
= label
;
1594 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
1595 info
.m_itemId
= index
;
1596 return InsertItem(info
);
1599 // For list view mode (only), inserts a column.
1600 long wxListCtrl::InsertColumn(long col
, const wxListItem
& item
)
1603 wxConvertToMSWListCol(GetHwnd(), col
, item
, lvCol
);
1605 if ( !(lvCol
.mask
& LVCF_WIDTH
) )
1607 // always give some width to the new column: this one is compatible
1608 // with the generic version
1609 lvCol
.mask
|= LVCF_WIDTH
;
1613 long n
= ListView_InsertColumn(GetHwnd(), col
, &lvCol
);
1618 else // failed to insert?
1620 wxLogDebug(wxT("Failed to insert the column '%s' into listview!"),
1627 long wxListCtrl::InsertColumn(long col
,
1628 const wxString
& heading
,
1633 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
1634 item
.m_text
= heading
;
1637 item
.m_mask
|= wxLIST_MASK_WIDTH
;
1638 item
.m_width
= width
;
1640 item
.m_format
= format
;
1642 return InsertColumn(col
, item
);
1645 // scroll the control by the given number of pixels (exception: in list view,
1646 // dx is interpreted as number of columns)
1647 bool wxListCtrl::ScrollList(int dx
, int dy
)
1649 if ( !ListView_Scroll(GetHwnd(), dx
, dy
) )
1651 wxLogDebug(_T("ListView_Scroll(%d, %d) failed"), dx
, dy
);
1661 // fn is a function which takes 3 long arguments: item1, item2, data.
1662 // item1 is the long data associated with a first item (NOT the index).
1663 // item2 is the long data associated with a second item (NOT the index).
1664 // data is the same value as passed to SortItems.
1665 // The return value is a negative number if the first item should precede the second
1666 // item, a positive number of the second item should precede the first,
1667 // or zero if the two items are equivalent.
1669 // data is arbitrary data to be passed to the sort function.
1671 // Internal structures for proxying the user compare function
1672 // so that we can pass it the *real* user data
1674 // translate lParam data and call user func
1675 struct wxInternalDataSort
1677 wxListCtrlCompare user_fn
;
1681 int CALLBACK
wxInternalDataCompareFunc(LPARAM lParam1
, LPARAM lParam2
, LPARAM lParamSort
)
1683 struct wxInternalDataSort
*internalData
= (struct wxInternalDataSort
*) lParamSort
;
1685 wxListItemInternalData
*data1
= (wxListItemInternalData
*) lParam1
;
1686 wxListItemInternalData
*data2
= (wxListItemInternalData
*) lParam2
;
1688 long d1
= (data1
== NULL
? 0 : data1
->lParam
);
1689 long d2
= (data2
== NULL
? 0 : data2
->lParam
);
1691 return internalData
->user_fn(d1
, d2
, internalData
->data
);
1695 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
1697 struct wxInternalDataSort internalData
;
1698 internalData
.user_fn
= fn
;
1699 internalData
.data
= data
;
1701 // WPARAM cast is needed for mingw/cygwin
1702 if ( !ListView_SortItems(GetHwnd(),
1703 wxInternalDataCompareFunc
,
1704 (WPARAM
) &internalData
) )
1706 wxLogDebug(_T("ListView_SortItems() failed"));
1716 // ----------------------------------------------------------------------------
1717 // message processing
1718 // ----------------------------------------------------------------------------
1720 bool wxListCtrl::MSWCommand(WXUINT cmd
, WXWORD id
)
1722 if (cmd
== EN_UPDATE
)
1724 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, id
);
1725 event
.SetEventObject( this );
1726 ProcessCommand(event
);
1729 else if (cmd
== EN_KILLFOCUS
)
1731 wxCommandEvent
event(wxEVT_KILL_FOCUS
, id
);
1732 event
.SetEventObject( this );
1733 ProcessCommand(event
);
1740 bool wxListCtrl::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
1743 // prepare the event
1744 // -----------------
1746 wxListEvent
event(wxEVT_NULL
, m_windowId
);
1747 event
.SetEventObject(this);
1749 wxEventType eventType
= wxEVT_NULL
;
1751 NMHDR
*nmhdr
= (NMHDR
*)lParam
;
1753 // if your compiler is as broken as this, you should really change it: this
1754 // code is needed for normal operation! #ifdef below is only useful for
1755 // automatic rebuilds which are done with a very old compiler version
1756 #ifdef HDN_BEGINTRACKA
1758 // check for messages from the header (in report view)
1759 HWND hwndHdr
= ListView_GetHeader(GetHwnd());
1761 // is it a message from the header?
1762 if ( nmhdr
->hwndFrom
== hwndHdr
)
1764 HD_NOTIFY
*nmHDR
= (HD_NOTIFY
*)nmhdr
;
1766 event
.m_itemIndex
= -1;
1768 switch ( nmhdr
->code
)
1770 // yet another comctl32.dll bug: under NT/W2K it sends Unicode
1771 // TRACK messages even to ANSI programs: on my system I get
1772 // HDN_BEGINTRACKW and HDN_ENDTRACKA and no HDN_TRACK at all!
1774 // work around is to simply catch both versions and hope that it
1775 // works (why should this message exist in ANSI and Unicode is
1776 // beyond me as it doesn't deal with strings at all...)
1778 // note that fr HDN_TRACK another possibility could be to use
1779 // HDN_ITEMCHANGING but it is sent even after HDN_ENDTRACK and when
1780 // something other than the item width changes so we'd have to
1781 // filter out the unwanted events then
1782 case HDN_BEGINTRACKA
:
1783 case HDN_BEGINTRACKW
:
1784 eventType
= wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
;
1789 if ( eventType
== wxEVT_NULL
)
1790 eventType
= wxEVT_COMMAND_LIST_COL_DRAGGING
;
1795 if ( eventType
== wxEVT_NULL
)
1796 eventType
= wxEVT_COMMAND_LIST_COL_END_DRAG
;
1798 event
.m_item
.m_width
= nmHDR
->pitem
->cxy
;
1799 event
.m_col
= nmHDR
->iItem
;
1802 #if defined(__WXWINCE__) && !defined(__HANDHELDPC__) && _WIN32_WCE < 400
1803 case GN_CONTEXTMENU
:
1804 #endif //__WXWINCE__
1807 eventType
= wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
;
1810 // find the column clicked: we have to search for it
1811 // ourselves as the notification message doesn't provide
1814 // where did the click occur?
1816 #if defined(__WXWINCE__) && !defined(__HANDHELDPC__) && _WIN32_WCE < 400
1817 if(nmhdr
->code
== GN_CONTEXTMENU
) {
1818 ptClick
= ((NMRGINFO
*)nmhdr
)->ptAction
;
1820 #endif //__WXWINCE__
1821 if ( !::GetCursorPos(&ptClick
) )
1823 wxLogLastError(_T("GetCursorPos"));
1826 if ( !::ScreenToClient(GetHwnd(), &ptClick
) )
1828 wxLogLastError(_T("ScreenToClient(listctrl header)"));
1831 event
.m_pointDrag
.x
= ptClick
.x
;
1832 event
.m_pointDrag
.y
= ptClick
.y
;
1834 int colCount
= Header_GetItemCount(hwndHdr
);
1837 for ( int col
= 0; col
< colCount
; col
++ )
1839 if ( Header_GetItemRect(hwndHdr
, col
, &rect
) )
1841 if ( ::PtInRect(&rect
, ptClick
) )
1851 case HDN_GETDISPINFOW
:
1852 // letting Windows XP handle this message results in mysterious
1853 // crashes in comctl32.dll seemingly because of bad message
1856 // I have no idea what is the real cause of the bug (which is,
1857 // just to make things interesting, is impossible to reproduce
1858 // reliably) but ignoring all these messages does fix it and
1859 // doesn't seem to have any negative consequences
1863 return wxControl::MSWOnNotify(idCtrl
, lParam
, result
);
1867 #endif // defined(HDN_BEGINTRACKA)
1868 if ( nmhdr
->hwndFrom
== GetHwnd() )
1870 // almost all messages use NM_LISTVIEW
1871 NM_LISTVIEW
*nmLV
= (NM_LISTVIEW
*)nmhdr
;
1873 const int iItem
= nmLV
->iItem
;
1876 // FreeAllInternalData will cause LVN_ITEMCHANG* messages, which can be
1877 // ignored for efficiency. It is done here because the internal data is in the
1878 // process of being deleted so we don't want to try and access it below.
1879 if ( m_ignoreChangeMessages
&&
1880 ( (nmLV
->hdr
.code
== LVN_ITEMCHANGED
) ||
1881 (nmLV
->hdr
.code
== LVN_ITEMCHANGING
)) )
1887 // If we have a valid item then check if there is a data value
1888 // associated with it and put it in the event.
1889 if ( iItem
>= 0 && iItem
< GetItemCount() )
1891 wxListItemInternalData
*internaldata
=
1892 wxGetInternalData(GetHwnd(), iItem
);
1895 event
.m_item
.m_data
= internaldata
->lParam
;
1898 bool processed
= true;
1899 switch ( nmhdr
->code
)
1901 case LVN_BEGINRDRAG
:
1902 eventType
= wxEVT_COMMAND_LIST_BEGIN_RDRAG
;
1906 if ( eventType
== wxEVT_NULL
)
1908 eventType
= wxEVT_COMMAND_LIST_BEGIN_DRAG
;
1911 event
.m_itemIndex
= iItem
;
1912 event
.m_pointDrag
.x
= nmLV
->ptAction
.x
;
1913 event
.m_pointDrag
.y
= nmLV
->ptAction
.y
;
1916 // NB: we have to handle both *A and *W versions here because some
1917 // versions of comctl32.dll send ANSI messages even to the
1919 case LVN_BEGINLABELEDITA
:
1920 case LVN_BEGINLABELEDITW
:
1923 if ( nmhdr
->code
== LVN_BEGINLABELEDITA
)
1925 item
.Init(((LV_DISPINFOA
*)lParam
)->item
);
1927 else // LVN_BEGINLABELEDITW
1929 item
.Init(((LV_DISPINFOW
*)lParam
)->item
);
1932 eventType
= wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
;
1933 wxConvertFromMSWListItem(GetHwnd(), event
.m_item
, item
);
1934 event
.m_itemIndex
= event
.m_item
.m_itemId
;
1938 case LVN_ENDLABELEDITA
:
1939 case LVN_ENDLABELEDITW
:
1942 if ( nmhdr
->code
== LVN_ENDLABELEDITA
)
1944 item
.Init(((LV_DISPINFOA
*)lParam
)->item
);
1946 else // LVN_ENDLABELEDITW
1948 item
.Init(((LV_DISPINFOW
*)lParam
)->item
);
1951 // was editing cancelled?
1952 const LV_ITEM
& lvi
= (LV_ITEM
)item
;
1953 if ( !lvi
.pszText
|| lvi
.iItem
== -1 )
1955 // don't keep a stale wxTextCtrl around
1958 // EDIT control will be deleted by the list control itself so
1959 // prevent us from deleting it as well
1960 m_textCtrl
->UnsubclassWin();
1961 m_textCtrl
->SetHWND(0);
1966 event
.SetEditCanceled(true);
1969 eventType
= wxEVT_COMMAND_LIST_END_LABEL_EDIT
;
1970 wxConvertFromMSWListItem(NULL
, event
.m_item
, item
);
1971 event
.m_itemIndex
= event
.m_item
.m_itemId
;
1975 case LVN_COLUMNCLICK
:
1976 eventType
= wxEVT_COMMAND_LIST_COL_CLICK
;
1977 event
.m_itemIndex
= -1;
1978 event
.m_col
= nmLV
->iSubItem
;
1981 case LVN_DELETEALLITEMS
:
1982 eventType
= wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
;
1983 event
.m_itemIndex
= -1;
1986 case LVN_DELETEITEM
:
1989 // this should be prevented by the post-processing code
1990 // below, but "just in case"
1994 eventType
= wxEVT_COMMAND_LIST_DELETE_ITEM
;
1995 event
.m_itemIndex
= iItem
;
1996 // delete the assoicated internal data
1997 wxDeleteInternalData(this, iItem
);
2000 #if WXWIN_COMPATIBILITY_2_4
2001 case LVN_SETDISPINFO
:
2003 eventType
= wxEVT_COMMAND_LIST_SET_INFO
;
2004 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
2005 wxConvertFromMSWListItem(GetHwnd(), event
.m_item
, info
->item
);
2010 case LVN_INSERTITEM
:
2011 eventType
= wxEVT_COMMAND_LIST_INSERT_ITEM
;
2012 event
.m_itemIndex
= iItem
;
2015 case LVN_ITEMCHANGED
:
2016 // we translate this catch all message into more interesting
2017 // (and more easy to process) wxWidgets events
2019 // first of all, we deal with the state change events only and
2020 // only for valid items (item == -1 for the virtual list
2022 if ( nmLV
->uChanged
& LVIF_STATE
&& iItem
!= -1 )
2024 // temp vars for readability
2025 const UINT stOld
= nmLV
->uOldState
;
2026 const UINT stNew
= nmLV
->uNewState
;
2028 event
.m_item
.SetId(iItem
);
2029 event
.m_item
.SetMask(wxLIST_MASK_TEXT
|
2032 GetItem(event
.m_item
);
2034 // has the focus changed?
2035 if ( !(stOld
& LVIS_FOCUSED
) && (stNew
& LVIS_FOCUSED
) )
2037 eventType
= wxEVT_COMMAND_LIST_ITEM_FOCUSED
;
2038 event
.m_itemIndex
= iItem
;
2041 if ( (stNew
& LVIS_SELECTED
) != (stOld
& LVIS_SELECTED
) )
2043 if ( eventType
!= wxEVT_NULL
)
2045 // focus and selection have both changed: send the
2046 // focus event from here and the selection one
2048 event
.SetEventType(eventType
);
2049 (void)GetEventHandler()->ProcessEvent(event
);
2051 else // no focus event to send
2053 // then need to set m_itemIndex as it wasn't done
2055 event
.m_itemIndex
= iItem
;
2058 eventType
= stNew
& LVIS_SELECTED
2059 ? wxEVT_COMMAND_LIST_ITEM_SELECTED
2060 : wxEVT_COMMAND_LIST_ITEM_DESELECTED
;
2064 if ( eventType
== wxEVT_NULL
)
2066 // not an interesting event for us
2074 LV_KEYDOWN
*info
= (LV_KEYDOWN
*)lParam
;
2075 WORD wVKey
= info
->wVKey
;
2077 // get the current selection
2078 long lItem
= GetNextItem(-1,
2080 wxLIST_STATE_SELECTED
);
2082 // <Enter> or <Space> activate the selected item if any (but
2083 // not with Shift and/or Ctrl as then they have a predefined
2084 // meaning for the list view)
2086 (wVKey
== VK_RETURN
|| wVKey
== VK_SPACE
) &&
2087 !(wxIsShiftDown() || wxIsCtrlDown()) )
2089 eventType
= wxEVT_COMMAND_LIST_ITEM_ACTIVATED
;
2093 eventType
= wxEVT_COMMAND_LIST_KEY_DOWN
;
2095 // wxCharCodeMSWToWX() returns 0 if the key is an ASCII
2096 // value which should be used as is
2097 int code
= wxCharCodeMSWToWX(wVKey
);
2098 event
.m_code
= code
? code
: wVKey
;
2102 event
.m_item
.m_itemId
= lItem
;
2106 // fill the other fields too
2107 event
.m_item
.m_text
= GetItemText(lItem
);
2108 event
.m_item
.m_data
= GetItemData(lItem
);
2114 // if the user processes it in wxEVT_COMMAND_LEFT_CLICK(), don't do
2116 if ( wxControl::MSWOnNotify(idCtrl
, lParam
, result
) )
2121 // else translate it into wxEVT_COMMAND_LIST_ITEM_ACTIVATED event
2122 // if it happened on an item (and not on empty place)
2129 eventType
= wxEVT_COMMAND_LIST_ITEM_ACTIVATED
;
2130 event
.m_itemIndex
= iItem
;
2131 event
.m_item
.m_text
= GetItemText(iItem
);
2132 event
.m_item
.m_data
= GetItemData(iItem
);
2135 #if defined(__WXWINCE__) && !defined(__HANDHELDPC__) && _WIN32_WCE < 400
2136 case GN_CONTEXTMENU
:
2137 #endif //__WXWINCE__
2139 // if the user processes it in wxEVT_COMMAND_RIGHT_CLICK(),
2140 // don't do anything else
2141 if ( wxControl::MSWOnNotify(idCtrl
, lParam
, result
) )
2146 // else translate it into wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK event
2147 LV_HITTESTINFO lvhti
;
2148 wxZeroMemory(lvhti
);
2150 #if defined(__WXWINCE__) && !defined(__HANDHELDPC__) && _WIN32_WCE < 400
2151 if(nmhdr
->code
== GN_CONTEXTMENU
) {
2152 lvhti
.pt
= ((NMRGINFO
*)nmhdr
)->ptAction
;
2154 #endif //__WXWINCE__
2155 ::GetCursorPos(&(lvhti
.pt
));
2156 ::ScreenToClient(GetHwnd(),&(lvhti
.pt
));
2157 if ( ListView_HitTest(GetHwnd(),&lvhti
) != -1 )
2159 if ( lvhti
.flags
& LVHT_ONITEM
)
2161 eventType
= wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
;
2162 event
.m_itemIndex
= lvhti
.iItem
;
2163 event
.m_pointDrag
.x
= lvhti
.pt
.x
;
2164 event
.m_pointDrag
.y
= lvhti
.pt
.y
;
2169 #ifdef NM_CUSTOMDRAW
2171 *result
= OnCustomDraw(lParam
);
2173 return *result
!= CDRF_DODEFAULT
;
2174 #endif // _WIN32_IE >= 0x300
2176 case LVN_ODCACHEHINT
:
2178 const NM_CACHEHINT
*cacheHint
= (NM_CACHEHINT
*)lParam
;
2180 eventType
= wxEVT_COMMAND_LIST_CACHE_HINT
;
2182 // we get some really stupid cache hints like ones for
2183 // items in range 0..0 for an empty control or, after
2184 // deleting an item, for items in invalid range -- filter
2186 if ( cacheHint
->iFrom
> cacheHint
->iTo
)
2189 event
.m_oldItemIndex
= cacheHint
->iFrom
;
2191 const long iMax
= GetItemCount();
2192 event
.m_itemIndex
= cacheHint
->iTo
< iMax
? cacheHint
->iTo
2197 #ifdef HAVE_NMLVFINDITEM
2198 case LVN_ODFINDITEM
:
2199 // this message is only used with the virtual list control but
2200 // even there we don't want to always use it: in a control with
2201 // sufficiently big number of items (defined as > 1000 here),
2202 // accidentally pressing a key could result in hanging an
2203 // application waiting while it performs linear search
2204 if ( IsVirtual() && GetItemCount() <= 1000 )
2206 NMLVFINDITEM
* pFindInfo
= (NMLVFINDITEM
*)lParam
;
2208 // no match by default
2211 // we only handle string-based searches here
2213 // TODO: what about LVFI_PARTIAL, should we handle this?
2214 if ( !(pFindInfo
->lvfi
.flags
& LVFI_STRING
) )
2219 const wxChar
* const searchstr
= pFindInfo
->lvfi
.psz
;
2220 const size_t len
= wxStrlen(searchstr
);
2222 // this is the first item we should examine, search from it
2223 // wrapping if necessary
2224 const int startPos
= pFindInfo
->iStart
;
2225 const int maxPos
= GetItemCount();
2226 wxCHECK_MSG( startPos
<= maxPos
, false,
2227 _T("bad starting position in LVN_ODFINDITEM") );
2229 int currentPos
= startPos
;
2232 // wrap to the beginning if necessary
2233 if ( currentPos
== maxPos
)
2235 // somewhat surprizingly, LVFI_WRAP isn't set in
2236 // flags but we still should wrap
2240 // does this item begin with searchstr?
2241 if ( wxStrnicmp(searchstr
,
2242 GetItemText(currentPos
), len
) == 0 )
2244 *result
= currentPos
;
2248 while ( ++currentPos
!= startPos
);
2250 if ( *result
== -1 )
2256 SetItemState(*result
,
2257 wxLIST_STATE_SELECTED
| wxLIST_STATE_FOCUSED
,
2258 wxLIST_STATE_SELECTED
| wxLIST_STATE_FOCUSED
);
2259 EnsureVisible(*result
);
2267 #endif // HAVE_NMLVFINDITEM
2269 case LVN_GETDISPINFO
:
2272 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
2274 LV_ITEM
& lvi
= info
->item
;
2275 long item
= lvi
.iItem
;
2277 if ( lvi
.mask
& LVIF_TEXT
)
2279 wxString text
= OnGetItemText(item
, lvi
.iSubItem
);
2280 wxStrncpy(lvi
.pszText
, text
, lvi
.cchTextMax
);
2283 // see comment at the end of wxListCtrl::GetColumn()
2284 #ifdef NM_CUSTOMDRAW
2285 if ( lvi
.mask
& LVIF_IMAGE
)
2287 lvi
.iImage
= OnGetItemColumnImage(item
, lvi
.iSubItem
);
2289 #endif // NM_CUSTOMDRAW
2291 // a little dose of healthy paranoia: as we never use
2292 // LVM_SETCALLBACKMASK we're not supposed to get these ones
2293 wxASSERT_MSG( !(lvi
.mask
& LVIF_STATE
),
2294 _T("we don't support state callbacks yet!") );
2305 return wxControl::MSWOnNotify(idCtrl
, lParam
, result
);
2309 // where did this one come from?
2313 // process the event
2314 // -----------------
2316 event
.SetEventType(eventType
);
2318 bool processed
= GetEventHandler()->ProcessEvent(event
);
2322 switch ( nmhdr
->code
)
2324 case LVN_DELETEALLITEMS
:
2325 // always return true to suppress all additional LVN_DELETEITEM
2326 // notifications - this makes deleting all items from a list ctrl
2330 // also, we may free all user data now (couldn't do it before as
2331 // the user should have access to it in OnDeleteAllItems() handler)
2332 FreeAllInternalData();
2334 // the control is empty now, synchronize the cached number of items
2335 // with the real one
2339 case LVN_ENDLABELEDITA
:
2340 case LVN_ENDLABELEDITW
:
2341 // logic here is inverted compared to all the other messages
2342 *result
= event
.IsAllowed();
2344 // don't keep a stale wxTextCtrl around
2347 // EDIT control will be deleted by the list control itself so
2348 // prevent us from deleting it as well
2349 m_textCtrl
->UnsubclassWin();
2350 m_textCtrl
->SetHWND(0);
2359 *result
= !event
.IsAllowed();
2364 // ----------------------------------------------------------------------------
2365 // custom draw stuff
2366 // ----------------------------------------------------------------------------
2368 // see comment at the end of wxListCtrl::GetColumn()
2369 #ifdef NM_CUSTOMDRAW // _WIN32_IE >= 0x0300
2371 static RECT
GetCustomDrawnItemRect(const NMCUSTOMDRAW
& nmcd
)
2374 ListView_GetItemRect(nmcd
.hdr
.hwndFrom
, nmcd
.dwItemSpec
, &rc
, LVIR_BOUNDS
);
2377 ListView_GetItemRect(nmcd
.hdr
.hwndFrom
, nmcd
.dwItemSpec
, &rcIcon
, LVIR_ICON
);
2379 // exclude the icon part, neither the selection background nor focus rect
2381 rc
.left
= rcIcon
.right
;
2386 static void HandleSubItemPrepaint(LPNMLVCUSTOMDRAW pLVCD
, HFONT hfont
)
2388 NMCUSTOMDRAW
& nmcd
= pLVCD
->nmcd
;
2391 HWND hwndList
= nmcd
.hdr
.hwndFrom
;
2392 const DWORD item
= nmcd
.dwItemSpec
;
2395 // the font must be valid, otherwise we wouldn't be painting the item at all
2396 SelectInHDC
selFont(hdc
, hfont
);
2398 // get the rectangle to paint
2400 ListView_GetSubItemRect(hwndList
, item
, pLVCD
->iSubItem
, LVIR_BOUNDS
, &rc
);
2401 if ( !pLVCD
->iSubItem
)
2403 // broken ListView_GetSubItemRect() returns the entire item rect for
2404 // 0th subitem while we really need just the part for this column
2406 ListView_GetSubItemRect(hwndList
, item
, 1, LVIR_BOUNDS
, &rc2
);
2408 rc
.right
= rc2
.left
;
2411 else // not first subitem
2416 // get the image and text to draw
2420 it
.mask
= LVIF_TEXT
| LVIF_IMAGE
;
2422 it
.iSubItem
= pLVCD
->iSubItem
;
2424 it
.cchTextMax
= WXSIZEOF(text
);
2425 ListView_GetItem(hwndList
, &it
);
2427 HIMAGELIST himl
= ListView_GetImageList(hwndList
, LVSIL_SMALL
);
2428 if ( himl
&& ImageList_GetImageCount(himl
) )
2430 if ( it
.iImage
!= -1 )
2432 ImageList_Draw(himl
, it
.iImage
, hdc
, rc
.left
, rc
.top
,
2433 nmcd
.uItemState
& CDIS_SELECTED
? ILD_SELECTED
2437 // notice that even if this item doesn't have any image, the list
2438 // control still leaves space for the image in the first column if the
2439 // image list is not empty (presumably so that items with and without
2441 if ( it
.iImage
!= -1 || it
.iSubItem
== 0 )
2444 ImageList_GetIconSize(himl
, &wImage
, &hImage
);
2446 rc
.left
+= wImage
+ 2;
2450 ::SetBkMode(hdc
, TRANSPARENT
);
2452 // TODO: support for centred/right aligned columns
2453 ::DrawText(hdc
, text
, -1, &rc
,
2456 #endif // __WXWINCE__
2457 DT_NOPREFIX
| DT_SINGLELINE
| DT_VCENTER
);
2460 static void HandleItemPostpaint(NMCUSTOMDRAW nmcd
)
2462 if ( nmcd
.uItemState
& CDIS_FOCUS
)
2464 RECT rc
= GetCustomDrawnItemRect(nmcd
);
2466 // don't use the provided HDC, it's in some strange state by now
2467 ::DrawFocusRect(WindowHDC(nmcd
.hdr
.hwndFrom
), &rc
);
2471 // pLVCD->clrText and clrTextBk should contain the colours to use
2472 static void HandleItemPaint(LPNMLVCUSTOMDRAW pLVCD
, HFONT hfont
)
2474 NMCUSTOMDRAW
& nmcd
= pLVCD
->nmcd
; // just a shortcut
2476 const HWND hwndList
= nmcd
.hdr
.hwndFrom
;
2477 const int item
= nmcd
.dwItemSpec
;
2479 // unfortunately we can't trust CDIS_SELECTED, it is often set even when
2480 // the item is not at all selected for some reason (comctl32 6), but we
2481 // also can't always trust ListView_GetItem() as it could return the old
2482 // item status if we're called just after the (de)selection, so remember
2483 // the last item to gain selection and also check for it here
2484 for ( int i
= -1;; )
2486 i
= ListView_GetNextItem(hwndList
, i
, LVNI_SELECTED
);
2489 nmcd
.uItemState
&= ~CDIS_SELECTED
;
2495 nmcd
.uItemState
|= CDIS_SELECTED
;
2500 // same thing for CDIS_FOCUS (except simpler as there is only one of them)
2501 if ( ::GetFocus() == hwndList
&&
2502 ListView_GetNextItem(hwndList
, (WPARAM
)-1, LVNI_FOCUSED
) == item
)
2504 nmcd
.uItemState
|= CDIS_FOCUS
;
2508 nmcd
.uItemState
&= ~CDIS_FOCUS
;
2511 if ( nmcd
.uItemState
& CDIS_SELECTED
)
2513 int syscolFg
, syscolBg
;
2514 if ( ::GetFocus() == hwndList
)
2516 syscolFg
= COLOR_HIGHLIGHTTEXT
;
2517 syscolBg
= COLOR_HIGHLIGHT
;
2519 else // selected but unfocused
2521 syscolFg
= COLOR_WINDOWTEXT
;
2522 syscolBg
= COLOR_BTNFACE
;
2524 // don't grey out the icon in this case neither
2525 nmcd
.uItemState
&= ~CDIS_SELECTED
;
2528 pLVCD
->clrText
= ::GetSysColor(syscolFg
);
2529 pLVCD
->clrTextBk
= ::GetSysColor(syscolBg
);
2531 //else: not selected, use normal colours from pLVCD
2534 RECT rc
= GetCustomDrawnItemRect(nmcd
);
2536 ::SetTextColor(hdc
, pLVCD
->clrText
);
2537 ::FillRect(hdc
, &rc
, AutoHBRUSH(pLVCD
->clrTextBk
));
2539 // we could use CDRF_NOTIFYSUBITEMDRAW here but it results in weird repaint
2540 // problems so just draw everything except the focus rect from here instead
2541 const int colCount
= Header_GetItemCount(ListView_GetHeader(hwndList
));
2542 for ( int col
= 0; col
< colCount
; col
++ )
2544 pLVCD
->iSubItem
= col
;
2545 HandleSubItemPrepaint(pLVCD
, hfont
);
2548 HandleItemPostpaint(nmcd
);
2551 static WXLPARAM
HandleItemPrepaint(wxListCtrl
*listctrl
,
2552 LPNMLVCUSTOMDRAW pLVCD
,
2553 wxListItemAttr
*attr
)
2557 // nothing to do for this item
2558 return CDRF_DODEFAULT
;
2562 // set the colours to use for text drawing
2563 pLVCD
->clrText
= attr
->HasTextColour()
2564 ? wxColourToRGB(attr
->GetTextColour())
2565 : wxColourToRGB(listctrl
->GetTextColour());
2566 pLVCD
->clrTextBk
= attr
->HasBackgroundColour()
2567 ? wxColourToRGB(attr
->GetBackgroundColour())
2568 : wxColourToRGB(listctrl
->GetBackgroundColour());
2570 // select the font if non default one is specified
2571 if ( attr
->HasFont() )
2573 wxFont font
= attr
->GetFont();
2574 if ( font
.GetEncoding() != wxFONTENCODING_SYSTEM
)
2576 // the standard control ignores the font encoding/charset, at least
2577 // with recent comctl32.dll versions (5 and 6, it uses to work with
2578 // 4.something) so we have to draw the item entirely ourselves in
2580 HandleItemPaint(pLVCD
, GetHfontOf(font
));
2581 return CDRF_SKIPDEFAULT
;
2584 ::SelectObject(pLVCD
->nmcd
.hdc
, GetHfontOf(font
));
2586 return CDRF_NEWFONT
;
2589 return CDRF_DODEFAULT
;
2592 WXLPARAM
wxListCtrl::OnCustomDraw(WXLPARAM lParam
)
2594 LPNMLVCUSTOMDRAW pLVCD
= (LPNMLVCUSTOMDRAW
)lParam
;
2595 NMCUSTOMDRAW
& nmcd
= pLVCD
->nmcd
;
2596 switch ( nmcd
.dwDrawStage
)
2599 // if we've got any items with non standard attributes,
2600 // notify us before painting each item
2602 // for virtual controls, always suppose that we have attributes as
2603 // there is no way to check for this
2604 if ( IsVirtual() || m_hasAnyAttr
)
2605 return CDRF_NOTIFYITEMDRAW
;
2608 case CDDS_ITEMPREPAINT
:
2609 const int item
= nmcd
.dwItemSpec
;
2611 // we get this message with item == 0 for an empty control, we
2612 // must ignore it as calling OnGetItemAttr() would be wrong
2613 if ( item
< 0 || item
>= GetItemCount() )
2616 return HandleItemPrepaint(this, pLVCD
, DoGetItemAttr(item
));
2619 return CDRF_DODEFAULT
;
2622 #endif // NM_CUSTOMDRAW supported
2624 // Necessary for drawing hrules and vrules, if specified
2625 void wxListCtrl::OnPaint(wxPaintEvent
& event
)
2627 bool drawHRules
= HasFlag(wxLC_HRULES
);
2628 bool drawVRules
= HasFlag(wxLC_VRULES
);
2630 if (!InReportView() || !drawHRules
&& !drawVRules
)
2638 wxControl::OnPaint(event
);
2640 // Reset the device origin since it may have been set
2641 dc
.SetDeviceOrigin(0, 0);
2643 wxPen
pen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
), 1, wxSOLID
);
2645 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
2647 wxSize clientSize
= GetClientSize();
2650 int itemCount
= GetItemCount();
2654 long top
= GetTopItem();
2655 for (i
= top
; i
< top
+ GetCountPerPage() + 1; i
++)
2657 if (GetItemRect(i
, itemRect
))
2659 int cy
= itemRect
.GetTop();
2660 if (i
!= 0) // Don't draw the first one
2662 dc
.DrawLine(0, cy
, clientSize
.x
, cy
);
2665 if (i
== itemCount
- 1)
2667 cy
= itemRect
.GetBottom();
2668 dc
.DrawLine(0, cy
, clientSize
.x
, cy
);
2674 if (drawVRules
&& (i
> -1))
2676 wxRect firstItemRect
;
2677 GetItemRect(0, firstItemRect
);
2679 if (GetItemRect(i
, itemRect
))
2681 // this is a fix for bug 673394: erase the pixels which we would
2682 // otherwise leave on the screen
2683 static const int gap
= 2;
2684 dc
.SetPen(*wxTRANSPARENT_PEN
);
2685 dc
.SetBrush(wxBrush(GetBackgroundColour()));
2686 dc
.DrawRectangle(0, firstItemRect
.GetY() - gap
,
2687 clientSize
.GetWidth(), gap
);
2690 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
2691 int x
= itemRect
.GetX();
2692 for (int col
= 0; col
< GetColumnCount(); col
++)
2694 int colWidth
= GetColumnWidth(col
);
2696 dc
.DrawLine(x
-1, firstItemRect
.GetY() - gap
,
2697 x
-1, itemRect
.GetBottom());
2704 wxListCtrl::MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
2710 // we should bypass our own WM_PRINT handling as we don't handle
2711 // PRF_CHILDREN flag, so leave it to the native control itself
2712 return MSWDefWindowProc(nMsg
, wParam
, lParam
);
2715 case WM_CONTEXTMENU
:
2716 // because this message is propagated upwards the child-parent
2717 // chain, we get it for the right clicks on the header window but
2718 // this is confusing in wx as right clicking there already
2719 // generates a separate wxEVT_COMMAND_LIST_COL_RIGHT_CLICK event
2720 // so just ignore them
2721 if ( (HWND
)wParam
== ListView_GetHeader(GetHwnd()) )
2726 return wxControl::MSWWindowProc(nMsg
, wParam
, lParam
);
2729 // ----------------------------------------------------------------------------
2730 // virtual list controls
2731 // ----------------------------------------------------------------------------
2733 wxString
wxListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
2735 // this is a pure virtual function, in fact - which is not really pure
2736 // because the controls which are not virtual don't need to implement it
2737 wxFAIL_MSG( _T("wxListCtrl::OnGetItemText not supposed to be called") );
2739 return wxEmptyString
;
2742 int wxListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
2744 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
2746 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
2750 int wxListCtrl::OnGetItemColumnImage(long item
, long column
) const
2753 return OnGetItemImage(item
);
2758 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
2760 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
2761 _T("invalid item index in OnGetItemAttr()") );
2763 // no attributes by default
2767 wxListItemAttr
*wxListCtrl::DoGetItemAttr(long item
) const
2769 return IsVirtual() ? OnGetItemAttr(item
)
2770 : wxGetInternalDataAttr(this, item
);
2773 void wxListCtrl::SetItemCount(long count
)
2775 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
2777 if ( !::SendMessage(GetHwnd(), LVM_SETITEMCOUNT
, (WPARAM
)count
,
2778 LVSICF_NOSCROLL
| LVSICF_NOINVALIDATEALL
) )
2780 wxLogLastError(_T("ListView_SetItemCount"));
2783 wxASSERT_MSG( m_count
== ListView_GetItemCount(GetHwnd()),
2784 wxT("m_count should match ListView_GetItemCount"));
2787 void wxListCtrl::RefreshItem(long item
)
2789 // strangely enough, ListView_Update() results in much more flicker here
2790 // than a dumb Refresh() -- why?
2792 if ( !ListView_Update(GetHwnd(), item
) )
2794 wxLogLastError(_T("ListView_Update"));
2798 GetItemRect(item
, rect
);
2803 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
2805 wxRect rect1
, rect2
;
2806 GetItemRect(itemFrom
, rect1
);
2807 GetItemRect(itemTo
, rect2
);
2809 wxRect rect
= rect1
;
2810 rect
.height
= rect2
.GetBottom() - rect1
.GetTop();
2815 // ----------------------------------------------------------------------------
2816 // internal data stuff
2817 // ----------------------------------------------------------------------------
2819 static wxListItemInternalData
*wxGetInternalData(HWND hwnd
, long itemId
)
2822 it
.mask
= LVIF_PARAM
;
2825 if ( !ListView_GetItem(hwnd
, &it
) )
2828 return (wxListItemInternalData
*) it
.lParam
;
2832 wxListItemInternalData
*wxGetInternalData(const wxListCtrl
*ctl
, long itemId
)
2834 return wxGetInternalData(GetHwndOf(ctl
), itemId
);
2838 wxListItemAttr
*wxGetInternalDataAttr(const wxListCtrl
*ctl
, long itemId
)
2840 wxListItemInternalData
*data
= wxGetInternalData(ctl
, itemId
);
2842 return data
? data
->attr
: NULL
;
2845 static void wxDeleteInternalData(wxListCtrl
* ctl
, long itemId
)
2847 wxListItemInternalData
*data
= wxGetInternalData(ctl
, itemId
);
2851 memset(&item
, 0, sizeof(item
));
2852 item
.iItem
= itemId
;
2853 item
.mask
= LVIF_PARAM
;
2854 item
.lParam
= (LPARAM
) 0;
2855 ListView_SetItem((HWND
)ctl
->GetHWND(), &item
);
2860 // ----------------------------------------------------------------------------
2861 // wxWin <-> MSW items conversions
2862 // ----------------------------------------------------------------------------
2864 static void wxConvertFromMSWListItem(HWND hwndListCtrl
,
2868 wxListItemInternalData
*internaldata
=
2869 (wxListItemInternalData
*) lvItem
.lParam
;
2872 info
.m_data
= internaldata
->lParam
;
2876 info
.m_stateMask
= 0;
2877 info
.m_itemId
= lvItem
.iItem
;
2879 long oldMask
= lvItem
.mask
;
2881 bool needText
= false;
2882 if (hwndListCtrl
!= 0)
2884 if ( lvItem
.mask
& LVIF_TEXT
)
2891 lvItem
.pszText
= new wxChar
[513];
2892 lvItem
.cchTextMax
= 512;
2894 lvItem
.mask
|= LVIF_TEXT
| LVIF_IMAGE
| LVIF_PARAM
;
2895 ::SendMessage(hwndListCtrl
, LVM_GETITEM
, 0, (LPARAM
)& lvItem
);
2898 if ( lvItem
.mask
& LVIF_STATE
)
2900 info
.m_mask
|= wxLIST_MASK_STATE
;
2902 if ( lvItem
.stateMask
& LVIS_CUT
)
2904 info
.m_stateMask
|= wxLIST_STATE_CUT
;
2905 if ( lvItem
.state
& LVIS_CUT
)
2906 info
.m_state
|= wxLIST_STATE_CUT
;
2908 if ( lvItem
.stateMask
& LVIS_DROPHILITED
)
2910 info
.m_stateMask
|= wxLIST_STATE_DROPHILITED
;
2911 if ( lvItem
.state
& LVIS_DROPHILITED
)
2912 info
.m_state
|= wxLIST_STATE_DROPHILITED
;
2914 if ( lvItem
.stateMask
& LVIS_FOCUSED
)
2916 info
.m_stateMask
|= wxLIST_STATE_FOCUSED
;
2917 if ( lvItem
.state
& LVIS_FOCUSED
)
2918 info
.m_state
|= wxLIST_STATE_FOCUSED
;
2920 if ( lvItem
.stateMask
& LVIS_SELECTED
)
2922 info
.m_stateMask
|= wxLIST_STATE_SELECTED
;
2923 if ( lvItem
.state
& LVIS_SELECTED
)
2924 info
.m_state
|= wxLIST_STATE_SELECTED
;
2928 if ( lvItem
.mask
& LVIF_TEXT
)
2930 info
.m_mask
|= wxLIST_MASK_TEXT
;
2931 info
.m_text
= lvItem
.pszText
;
2933 if ( lvItem
.mask
& LVIF_IMAGE
)
2935 info
.m_mask
|= wxLIST_MASK_IMAGE
;
2936 info
.m_image
= lvItem
.iImage
;
2938 if ( lvItem
.mask
& LVIF_PARAM
)
2939 info
.m_mask
|= wxLIST_MASK_DATA
;
2940 if ( lvItem
.mask
& LVIF_DI_SETITEM
)
2941 info
.m_mask
|= wxLIST_SET_ITEM
;
2942 info
.m_col
= lvItem
.iSubItem
;
2947 delete[] lvItem
.pszText
;
2949 lvItem
.mask
= oldMask
;
2952 static void wxConvertToMSWFlags(long state
, long stateMask
, LV_ITEM
& lvItem
)
2954 if (stateMask
& wxLIST_STATE_CUT
)
2956 lvItem
.stateMask
|= LVIS_CUT
;
2957 if (state
& wxLIST_STATE_CUT
)
2958 lvItem
.state
|= LVIS_CUT
;
2960 if (stateMask
& wxLIST_STATE_DROPHILITED
)
2962 lvItem
.stateMask
|= LVIS_DROPHILITED
;
2963 if (state
& wxLIST_STATE_DROPHILITED
)
2964 lvItem
.state
|= LVIS_DROPHILITED
;
2966 if (stateMask
& wxLIST_STATE_FOCUSED
)
2968 lvItem
.stateMask
|= LVIS_FOCUSED
;
2969 if (state
& wxLIST_STATE_FOCUSED
)
2970 lvItem
.state
|= LVIS_FOCUSED
;
2972 if (stateMask
& wxLIST_STATE_SELECTED
)
2974 lvItem
.stateMask
|= LVIS_SELECTED
;
2975 if (state
& wxLIST_STATE_SELECTED
)
2976 lvItem
.state
|= LVIS_SELECTED
;
2980 static void wxConvertToMSWListItem(const wxListCtrl
*ctrl
,
2981 const wxListItem
& info
,
2984 lvItem
.iItem
= (int) info
.m_itemId
;
2986 lvItem
.iImage
= info
.m_image
;
2987 lvItem
.stateMask
= 0;
2990 lvItem
.iSubItem
= info
.m_col
;
2992 if (info
.m_mask
& wxLIST_MASK_STATE
)
2994 lvItem
.mask
|= LVIF_STATE
;
2996 wxConvertToMSWFlags(info
.m_state
, info
.m_stateMask
, lvItem
);
2999 if (info
.m_mask
& wxLIST_MASK_TEXT
)
3001 lvItem
.mask
|= LVIF_TEXT
;
3002 if ( ctrl
->HasFlag(wxLC_USER_TEXT
) )
3004 lvItem
.pszText
= LPSTR_TEXTCALLBACK
;
3008 // pszText is not const, hence the cast
3009 lvItem
.pszText
= (wxChar
*)info
.m_text
.c_str();
3010 if ( lvItem
.pszText
)
3011 lvItem
.cchTextMax
= info
.m_text
.length();
3013 lvItem
.cchTextMax
= 0;
3016 if (info
.m_mask
& wxLIST_MASK_IMAGE
)
3017 lvItem
.mask
|= LVIF_IMAGE
;
3020 static void wxConvertToMSWListCol(HWND hwndList
,
3022 const wxListItem
& item
,
3025 wxZeroMemory(lvCol
);
3027 if ( item
.m_mask
& wxLIST_MASK_TEXT
)
3029 lvCol
.mask
|= LVCF_TEXT
;
3030 lvCol
.pszText
= (wxChar
*)item
.m_text
.c_str(); // cast is safe
3033 if ( item
.m_mask
& wxLIST_MASK_FORMAT
)
3035 lvCol
.mask
|= LVCF_FMT
;
3037 if ( item
.m_format
== wxLIST_FORMAT_LEFT
)
3038 lvCol
.fmt
= LVCFMT_LEFT
;
3039 else if ( item
.m_format
== wxLIST_FORMAT_RIGHT
)
3040 lvCol
.fmt
= LVCFMT_RIGHT
;
3041 else if ( item
.m_format
== wxLIST_FORMAT_CENTRE
)
3042 lvCol
.fmt
= LVCFMT_CENTER
;
3045 if ( item
.m_mask
& wxLIST_MASK_WIDTH
)
3047 lvCol
.mask
|= LVCF_WIDTH
;
3048 if ( item
.m_width
== wxLIST_AUTOSIZE
)
3049 lvCol
.cx
= LVSCW_AUTOSIZE
;
3050 else if ( item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
3051 lvCol
.cx
= LVSCW_AUTOSIZE_USEHEADER
;
3053 lvCol
.cx
= item
.m_width
;
3056 // see comment at the end of wxListCtrl::GetColumn()
3057 #ifdef NM_CUSTOMDRAW // _WIN32_IE >= 0x0300
3058 if ( item
.m_mask
& wxLIST_MASK_IMAGE
)
3060 if ( wxApp::GetComCtl32Version() >= 470 )
3062 lvCol
.mask
|= LVCF_IMAGE
;
3064 // we use LVCFMT_BITMAP_ON_RIGHT because the images on the right
3065 // seem to be generally nicer than on the left and the generic
3066 // version only draws them on the right (we don't have a flag to
3067 // specify the image location anyhow)
3069 // we don't use LVCFMT_COL_HAS_IMAGES because it doesn't seem to
3070 // make any difference in my tests -- but maybe we should?
3071 if ( item
.m_image
!= -1 )
3073 // as we're going to overwrite the format field, get its
3074 // current value first -- unless we want to overwrite it anyhow
3075 if ( !(lvCol
.mask
& LVCF_FMT
) )
3078 wxZeroMemory(lvColOld
);
3079 lvColOld
.mask
= LVCF_FMT
;
3080 if ( ListView_GetColumn(hwndList
, col
, &lvColOld
) )
3082 lvCol
.fmt
= lvColOld
.fmt
;
3085 lvCol
.mask
|= LVCF_FMT
;
3088 lvCol
.fmt
|= LVCFMT_BITMAP_ON_RIGHT
| LVCFMT_IMAGE
;
3091 lvCol
.iImage
= item
.m_image
;
3093 //else: it doesn't support item images anyhow
3095 #endif // _WIN32_IE >= 0x0300
3098 #endif // wxUSE_LISTCTRL