X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/6aaef1403eaefd3f0b919963d7f231efb045e50c..15c3723c6092669f91c9251382f4a1521deeceeb:/src/msw/listctrl.cpp diff --git a/src/msw/listctrl.cpp b/src/msw/listctrl.cpp index ff95a5ce0e..2379386b1c 100644 --- a/src/msw/listctrl.cpp +++ b/src/msw/listctrl.cpp @@ -79,7 +79,7 @@ static void wxConvertToMSWListCol(int col, const wxListItem& item, // We have to handle both fooW and fooA notifications in several cases // because of broken commctl.dll and/or unicows.dll. This class is used to -// convert LV_ITEMA and LV_ITEMW to LV_ITEM (which is either LV_ITEMA or +// convert LV_ITEMA and LV_ITEMW to LV_ITEM (which is either LV_ITEMA or // LV_ITEMW depending on wxUSE_UNICODE setting), so that it can be processed // by wxConvertToMSWListItem(). class wxLV_ITEM @@ -100,7 +100,7 @@ public: } else m_buf = NULL; - } + } private: wxMB2WXbuf *m_buf; @@ -115,7 +115,7 @@ private: } else m_buf = NULL; - } + } wxLV_ITEM(LV_ITEMA &item) : m_buf(NULL), m_item(&item) {} private: wxWC2WXbuf *m_buf; @@ -126,32 +126,32 @@ private: /////////////////////////////////////////////////////// // Problem: -// The MSW version had problems with SetTextColour() et -// al as the wxListItemAttr's were stored keyed on the -// item index. If a item was inserted anywhere but the end -// of the list the the text attributes (colour etc) for +// The MSW version had problems with SetTextColour() et +// al as the wxListItemAttr's were stored keyed on the +// item index. If a item was inserted anywhere but the end +// of the list the the text attributes (colour etc) for // the following items were out of sync. -// +// // Solution: -// Under MSW the only way to associate data with a List -// item independant of its position in the list is to -// store a pointer to it in its lParam attribute. However -// user programs are already using this (via the +// Under MSW the only way to associate data with a List +// item independant of its position in the list is to +// store a pointer to it in its lParam attribute. However +// user programs are already using this (via the // SetItemData() GetItemData() calls). -// -// However what we can do is store a pointer to a -// structure which contains the attributes we want *and* +// +// However what we can do is store a pointer to a +// structure which contains the attributes we want *and* // a lParam for the users data, e.g. -// +// // class wxListItemInternalData // { // public: -// wxListItemAttr *attr; +// wxListItemAttr *attr; // long lParam; // user data // }; -// -// To conserve memory, a wxListItemInternalData is -// only allocated for a LV_ITEM if text attributes or +// +// To conserve memory, a wxListItemInternalData is +// only allocated for a LV_ITEM if text attributes or // user data(lparam) are being set. @@ -159,7 +159,7 @@ private: class wxListItemInternalData { public: - wxListItemAttr *attr; + wxListItemAttr *attr; LPARAM lParam; // user data wxListItemInternalData() : attr(NULL), lParam(0) {} @@ -171,9 +171,10 @@ public: }; // Get the internal data structure -static wxListItemInternalData *GetInternalData(HWND hwnd, long itemId); -static wxListItemInternalData *GetInternalData(wxListCtrl *ctl, long itemId); -static wxListItemAttr *GetInternalDataAttr(wxListCtrl *ctl, long itemId); +static wxListItemInternalData *wxGetInternalData(HWND hwnd, long itemId); +static wxListItemInternalData *wxGetInternalData(wxListCtrl *ctl, long itemId); +static wxListItemAttr *wxGetInternalDataAttr(wxListCtrl *ctl, long itemId); +static void wxDeleteInternalData(wxListCtrl* ctl, long itemId); // ---------------------------------------------------------------------------- @@ -359,17 +360,15 @@ void wxListCtrl::UpdateStyle() void wxListCtrl::FreeAllInternalData() { if (m_AnyInternalData) - { + { int n = GetItemCount(); int i = 0; for (i = 0; i < n; i++) - { - wxListItemInternalData *data = GetInternalData(this, i); - if (data) - delete data; - }; - }; + wxDeleteInternalData(this, i); + + m_AnyInternalData = FALSE; + } } wxListCtrl::~wxListCtrl() @@ -580,6 +579,8 @@ bool wxListCtrl::GetColumn(int col, wxListItem& item) const LV_COLUMN lvCol; wxZeroMemory(lvCol); + lvCol.mask = LVCF_WIDTH; + if ( item.m_mask & wxLIST_MASK_TEXT ) { lvCol.mask |= LVCF_TEXT; @@ -587,7 +588,17 @@ bool wxListCtrl::GetColumn(int col, wxListItem& item) const lvCol.cchTextMax = 512; } - bool success = ListView_GetColumn(GetHwnd(), col, & lvCol) != 0; + if ( item.m_mask & wxLIST_MASK_FORMAT ) + { + lvCol.mask |= LVCF_FMT; + } + + if ( item.m_mask & wxLIST_MASK_IMAGE ) + { + lvCol.mask |= LVCF_IMAGE; + } + + bool success = ListView_GetColumn(GetHwnd(), col, &lvCol) != 0; // item.m_subItem = lvCol.iSubItem; item.m_width = lvCol.cx; @@ -600,14 +611,29 @@ bool wxListCtrl::GetColumn(int col, wxListItem& item) const if ( item.m_mask & wxLIST_MASK_FORMAT ) { - if (lvCol.fmt == LVCFMT_LEFT) - item.m_format = wxLIST_FORMAT_LEFT; - else if (lvCol.fmt == LVCFMT_RIGHT) - item.m_format = wxLIST_FORMAT_RIGHT; - else if (lvCol.fmt == LVCFMT_CENTER) - item.m_format = wxLIST_FORMAT_CENTRE; + switch (lvCol.fmt & LVCFMT_JUSTIFYMASK) { + case LVCFMT_LEFT: + item.m_format = wxLIST_FORMAT_LEFT; + break; + case LVCFMT_RIGHT: + item.m_format = wxLIST_FORMAT_RIGHT; + break; + case LVCFMT_CENTER: + item.m_format = wxLIST_FORMAT_CENTRE; + break; + default: + item.m_format = -1; // Unknown? + break; + } } +#if _WIN32_IE >= 0x0300 + if ( item.m_mask & wxLIST_MASK_IMAGE ) + { + item.m_image = lvCol.iImage; + } +#endif + return success; } @@ -723,8 +749,8 @@ bool wxListCtrl::SetItem(wxListItem& info) { // get internal item data // perhaps a cache here ? - wxListItemInternalData *data = GetInternalData(this, info.m_itemId); - + wxListItemInternalData *data = wxGetInternalData(this, info.m_itemId); + if (! data) { // need to set it @@ -1295,14 +1321,22 @@ long wxListCtrl::FindItem(long start, const wxString& str, bool partial) // Find an item whose data matches this data, starting from the item after 'start' // or the beginning if 'start' is -1. +// NOTE : Lindsay Mathieson - 14-July-2002 +// No longer use ListView_FindItem as the data attribute is now stored +// in a wxListItemInternalData structure refernced by the actual lParam long wxListCtrl::FindItem(long start, long data) { - LV_FINDINFO findInfo; + long idx = start + 1; + long count = GetItemCount(); - findInfo.flags = LVFI_PARAM; - findInfo.lParam = data; + while (idx < count) + { + if (GetItemData(idx) == data) + return idx; + idx++; + }; - return ListView_FindItem(GetHwnd(), (int) start, & findInfo); + return -1; } // Find an item nearest this position in the specified direction, starting from @@ -1728,7 +1762,7 @@ bool wxListCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) eventType = wxEVT_COMMAND_LIST_END_LABEL_EDIT; wxLV_ITEM item(((LV_DISPINFOA *)lParam)->item); wxConvertFromMSWListItem(NULL, event.m_item, item); - if ( ((LV_ITEM)item).pszText == NULL || + if ( ((LV_ITEM)item).pszText == NULL || ((LV_ITEM)item).iItem == -1 ) return FALSE; @@ -1740,7 +1774,7 @@ bool wxListCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) eventType = wxEVT_COMMAND_LIST_END_LABEL_EDIT; wxLV_ITEM item(((LV_DISPINFOW *)lParam)->item); wxConvertFromMSWListItem(NULL, event.m_item, item); - if ( ((LV_ITEM)item).pszText == NULL || + if ( ((LV_ITEM)item).pszText == NULL || ((LV_ITEM)item).iItem == -1 ) return FALSE; @@ -1762,14 +1796,8 @@ bool wxListCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) case LVN_DELETEITEM: eventType = wxEVT_COMMAND_LIST_DELETE_ITEM; event.m_itemIndex = nmLV->iItem; - // delete the assoicated internal data - { - wxListItemInternalData *data = - GetInternalData(this, nmLV->iItem); - if (data) - delete data; - }; + wxDeleteInternalData(this, nmLV->iItem); break; case LVN_SETDISPINFO: @@ -2060,7 +2088,7 @@ WXLPARAM wxListCtrl::OnCustomDraw(WXLPARAM lParam) wxListItemAttr *attr = IsVirtual() ? OnGetItemAttr(item) - : GetInternalDataAttr(this, item); + : wxGetInternalDataAttr(this, item); if ( !attr ) { @@ -2257,7 +2285,7 @@ void wxListCtrl::RefreshItems(long itemFrom, long itemTo) RefreshRect(rect); } -static wxListItemInternalData *GetInternalData(HWND hwnd, long itemId) +static wxListItemInternalData *wxGetInternalData(HWND hwnd, long itemId) { LV_ITEM it; it.mask = LVIF_PARAM; @@ -2270,26 +2298,40 @@ static wxListItemInternalData *GetInternalData(HWND hwnd, long itemId) return NULL; }; -static wxListItemInternalData *GetInternalData(wxListCtrl *ctl, long itemId) +static wxListItemInternalData *wxGetInternalData(wxListCtrl *ctl, long itemId) { - return GetInternalData((HWND) ctl->GetHWND(), itemId); + return wxGetInternalData((HWND) ctl->GetHWND(), itemId); }; -static wxListItemAttr *GetInternalDataAttr(wxListCtrl *ctl, long itemId) +static wxListItemAttr *wxGetInternalDataAttr(wxListCtrl *ctl, long itemId) { - wxListItemInternalData *data = GetInternalData(ctl, itemId); + wxListItemInternalData *data = wxGetInternalData(ctl, itemId); if (data) return data->attr; else return NULL; }; +static void wxDeleteInternalData(wxListCtrl* ctl, long itemId) +{ + wxListItemInternalData *data = wxGetInternalData(ctl, itemId); + if (data) + { + delete data; + LV_ITEM item; + memset(&item, 0, sizeof(item)); + item.iItem = itemId; + item.mask = LVIF_PARAM; + item.lParam = (LPARAM) 0; + ListView_SetItem((HWND)ctl->GetHWND(), &item); + } +} static void wxConvertFromMSWListItem(HWND hwndListCtrl, wxListItem& info, LV_ITEM& lvItem) { - wxListItemInternalData *internaldata = + wxListItemInternalData *internaldata = (wxListItemInternalData *) lvItem.lParam; if (internaldata)