#pragma hdrstop
#endif
-#ifdef __WIN95__
+#if wxUSE_LISTCTRL && defined(__WIN95__)
#ifndef WX_PRECOMP
#include "wx/app.h"
#include "wx/msw/private.h"
-#ifdef __GNUWIN32_OLD__
+#if ((defined(__GNUWIN32_OLD__) || defined(__TWIN32__)) && !defined(__CYGWIN10__))
#include "wx/msw/gnuwin32/extra.h"
#else
#include <commctrl.h>
#define LVS_EX_FULLROWSELECT 0x00000020
#endif
+#ifndef LVS_OWNERDATA
+ #define LVS_OWNERDATA 0x1000
+#endif
+
// ----------------------------------------------------------------------------
// private functions
// ----------------------------------------------------------------------------
DWORD wstyle = WS_VISIBLE | WS_CHILD | WS_TABSTOP |
LVS_SHAREIMAGELISTS | LVS_SHOWSELALWAYS;
+
+ if ( m_windowStyle & wxCLIP_SIBLINGS )
+ wstyle |= WS_CLIPSIBLINGS;
+
if ( wxStyleHasBorder(m_windowStyle) )
wstyle |= WS_BORDER;
m_baseStyle = wstyle;
if ( m_textCtrl )
{
- m_textCtrl->UnsubclassWin();
m_textCtrl->SetHWND(0);
+ m_textCtrl->UnsubclassWin();
delete m_textCtrl;
m_textCtrl = NULL;
}
-
+
if (m_ownsImageListNormal) delete m_imageListNormal;
if (m_ownsImageListSmall) delete m_imageListSmall;
if (m_ownsImageListState) delete m_imageListState;
if ( style & wxLC_AUTOARRANGE )
wstyle |= LVS_AUTOARRANGE;
- // Apparently, no such style (documentation wrong?)
- /*
- if ( style & wxLC_BUTTON )
- wstyle |= LVS_BUTTON;
- */
-
if ( style & wxLC_NO_SORT_HEADER )
wstyle |= LVS_NOSORTHEADER;
wstyle |= LVS_SORTDESCENDING;
}
+ if ( style & wxLC_VIRTUAL )
+ {
+ int ver = wxTheApp->GetComCtl32Version();
+ if ( ver < 470 )
+ {
+ wxLogWarning(_("Please install a newer version of comctl32.dll\n"
+ "(at least version 4.70 is required but you have "
+ "%d.%02d)\n"
+ "or this program won't operate correctly."),
+ ver / 100, ver % 100);
+ }
+
+ wstyle |= LVS_OWNERDATA;
+ }
+
return wstyle;
}
LV_ITEM item;
wxConvertToMSWListItem(this, info, item);
- // check whether it has any custom attributes
- if ( info.HasAttributes() )
+ item.cchTextMax = 0;
+ if ( !ListView_SetItem(GetHwnd(), &item) )
{
+ wxLogDebug(_T("ListView_SetItem() failed"));
- wxListItemAttr *attr;
- attr = (wxListItemAttr*) m_attrs.Get(item.iItem);
+ return FALSE;
+ }
- if (attr == NULL)
+ // we need to update the item immediately to show the new image
+ bool updateNow = (info.m_mask & wxLIST_MASK_IMAGE) != 0;
- m_attrs.Put(item.iItem, (wxObject *)new wxListItemAttr(*info.GetAttributes()));
+ // check whether it has any custom attributes
+ if ( info.HasAttributes() )
+ {
+ wxListItemAttr *attr = (wxListItemAttr *)m_attrs.Get(item.iItem);
- else *attr = *info.GetAttributes();
+ if ( attr == NULL )
+ m_attrs.Put(item.iItem, (wxObject *)new wxListItemAttr(*info.GetAttributes()));
+ else
+ *attr = *info.GetAttributes();
m_hasAnyAttr = TRUE;
+
+ // if the colour has changed, we must redraw the item
+ updateNow = TRUE;
}
- item.cchTextMax = 0;
- bool ok = ListView_SetItem(GetHwnd(), &item) != 0;
- if ( ok && (info.m_mask & wxLIST_MASK_IMAGE) )
+ if ( updateNow )
{
- // make the change visible
+ // we need this to make the change visible right now
ListView_Update(GetHwnd(), item.iItem);
}
- return ok;
+ return TRUE;
}
long wxListCtrl::SetItem(long index, int col, const wxString& label, int imageId)
}
// Sets the item image
-bool wxListCtrl::SetItemImage(long item, int image, int selImage)
+bool wxListCtrl::SetItemImage(long item, int image, int WXUNUSED(selImage))
{
wxListItem info;
{
wxASSERT( (textControlClass->IsKindOf(CLASSINFO(wxTextCtrl))) );
+ // VS: ListView_EditLabel requires that the list has focus.
+ SetFocus();
HWND hWnd = (HWND) ListView_EditLabel(GetHwnd(), item);
if (m_textCtrl)
{
- m_textCtrl->UnsubclassWin();
m_textCtrl->SetHWND(0);
+ m_textCtrl->UnsubclassWin();
delete m_textCtrl;
m_textCtrl = NULL;
}
}
// End label editing, optionally cancelling the edit
-bool wxListCtrl::EndEditLabel(bool cancel)
-{
- wxFAIL;
-
- /* I don't know how to implement this: there's no such macro as ListView_EndEditLabelNow.
- * ???
- bool success = (ListView_EndEditLabelNow(GetHwnd(), cancel) != 0);
-
- if (m_textCtrl)
- {
- m_textCtrl->UnsubclassWin();
- m_textCtrl->SetHWND(0);
- delete m_textCtrl;
- m_textCtrl = NULL;
- }
- return success;
- */
+bool wxListCtrl::EndEditLabel(bool WXUNUSED(cancel))
+{
+ wxFAIL_MSG( _T("not implemented") );
+
return FALSE;
}
-
// Ensures this item is visible
bool wxListCtrl::EnsureVisible(long item)
{
- return (ListView_EnsureVisible(GetHwnd(), (int) item, FALSE) != 0);
+ return ListView_EnsureVisible(GetHwnd(), (int) item, FALSE) != 0;
}
// Find an item whose label matches this string, starting from the item after 'start'
// -1 otherwise.
long wxListCtrl::InsertItem(wxListItem& info)
{
+ wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") );
+
LV_ITEM item;
wxConvertToMSWListItem(this, info, item);
eventType = wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT;
LV_DISPINFO *info = (LV_DISPINFO *)lParam;
wxConvertFromMSWListItem(this, event.m_item, info->item, GetHwnd());
+ event.m_itemIndex = event.m_item.m_itemId;
}
break;
wxConvertFromMSWListItem(this, event.m_item, info->item);
if ( info->item.pszText == NULL || info->item.iItem == -1 )
return FALSE;
+
+ event.m_itemIndex = event.m_item.m_itemId;
}
break;
}
break;
- case LVN_GETDISPINFO:
- // this provokes stack overflow: indeed, wxConvertFromMSWListItem()
- // sends us WM_NOTIFY! As it doesn't do anything for now, just leave
- // it out.
-#if 0
- {
- // TODO: some text buffering here, I think
- // TODO: API for getting Windows to retrieve values
- // on demand.
- eventType = wxEVT_COMMAND_LIST_GET_INFO;
- LV_DISPINFO *info = (LV_DISPINFO *)lParam;
- wxConvertFromMSWListItem(this, event.m_item, info->item, GetHwnd());
- break;
- }
-#endif // 0
- return FALSE;
-
-
case LVN_INSERTITEM:
eventType = wxEVT_COMMAND_LIST_INSERT_ITEM;
event.m_itemIndex = nmLV->iItem;
// break; // can never be reached
#endif // _WIN32_IE >= 0x300
+ case LVN_GETDISPINFO:
+ if ( IsVirtual() )
+ {
+ LV_DISPINFO *info = (LV_DISPINFO *)lParam;
+
+ LV_ITEM& lvi = info->item;
+ long item = lvi.iItem;
+
+ if ( lvi.mask & LVIF_TEXT )
+ {
+ wxString text = OnGetItemText(item, lvi.iSubItem);
+ wxStrncpy(lvi.pszText, text, lvi.cchTextMax);
+ }
+
+ if ( lvi.mask & LVIF_IMAGE )
+ {
+ lvi.iImage = OnGetItemImage(item);
+ }
+
+ // a little dose of healthy paranoia: as we never use
+ // LVM_SETCALLBACKMASK we're not supposed to get these ones
+ wxASSERT_MSG( !(lvi.mask & LVIF_STATE),
+ _T("we don't support state callbacks yet!") );
+
+ return TRUE;
+ }
+ // fall through
+
default:
return wxControl::MSWOnNotify(idCtrl, lParam, result);
}
return TRUE;
- case LVN_GETDISPINFO:
- {
- LV_DISPINFO *info = (LV_DISPINFO *)lParam;
- if ( info->item.mask & LVIF_TEXT )
- {
- if ( !event.m_item.m_text.IsNull() )
- {
- info->item.pszText = AddPool(event.m_item.m_text);
- info->item.cchTextMax = wxStrlen(info->item.pszText) + 1;
- }
- }
- // wxConvertToMSWListItem(this, event.m_item, info->item);
- break;
- }
case LVN_ENDLABELEDIT:
{
*result = event.IsAllowed();
return TRUE;
}
-wxChar *wxListCtrl::AddPool(const wxString& str)
-{
- // Remove the first element if 3 strings exist
- if ( m_stringPool.Number() == 3 )
- {
- wxNode *node = m_stringPool.First();
- delete[] (char *)node->Data();
- delete node;
- }
- wxNode *node = m_stringPool.Add(WXSTRINGCAST str);
- return (wxChar *)node->Data();
-}
-
// Necessary for drawing hrules and vrules, if specified
void wxListCtrl::OnPaint(wxPaintEvent& event)
{
}
}
+// ----------------------------------------------------------------------------
+// virtual list controls
+// ----------------------------------------------------------------------------
+
+wxString wxListCtrl::OnGetItemText(long item, long col) const
+{
+ // this is a pure virtual function, in fact - which is not really pure
+ // because the controls which are not virtual don't need to implement it
+ wxFAIL_MSG( _T("not supposed to be called") );
+
+ return wxEmptyString;
+}
+
+int wxListCtrl::OnGetItemImage(long item) const
+{
+ // same as above
+ wxFAIL_MSG( _T("not supposed to be called") );
+
+ return -1;
+}
+
+void wxListCtrl::SetItemCount(long count)
+{
+ wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
+
+ if ( !::SendMessage(GetHwnd(), LVM_SETITEMCOUNT, (WPARAM)count, 0) )
+ {
+ wxLogLastError(_T("ListView_SetItemCount"));
+ }
+}
+
// ----------------------------------------------------------------------------
// wxListItem
// ----------------------------------------------------------------------------
m_attr = NULL;
}
-static void wxConvertFromMSWListItem(const wxListCtrl *ctrl, wxListItem& info, LV_ITEM& lvItem, HWND getFullInfo)
+static void wxConvertFromMSWListItem(const wxListCtrl *WXUNUSED(ctrl), wxListItem& info, LV_ITEM& lvItem, HWND getFullInfo)
{
info.m_data = lvItem.lParam;
info.m_mask = 0;
}
else
{
- lvItem.pszText = WXSTRINGCAST info.m_text;
+ // pszText is not const, hence the cast
+ lvItem.pszText = (wxChar *)info.m_text.c_str();
if ( lvItem.pszText )
lvItem.cchTextMax = info.m_text.Length();
else
m_cancelled = FALSE;
}
-#endif // __WIN95__
-
+#endif // wxUSE_LISTCTRL