X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/26df5dd39a8c09397b19cd98ea51600af5a1dea4..76274efd346219516fbc8f04c4546beb1e859f9e:/src/msw/listctrl.cpp?ds=sidebyside diff --git a/src/msw/listctrl.cpp b/src/msw/listctrl.cpp index 45e1d0c503..abfdf8db89 100644 --- a/src/msw/listctrl.cpp +++ b/src/msw/listctrl.cpp @@ -1333,6 +1333,29 @@ void wxListCtrl::AssignImageList(wxImageList *imageList, int which) m_ownsImageListState = true; } +// ---------------------------------------------------------------------------- +// Geometry +// ---------------------------------------------------------------------------- + +wxSize wxListCtrl::MSWGetBestViewRect(int x, int y) const +{ + const DWORD rc = ListView_ApproximateViewRect(GetHwnd(), x, y, -1); + + wxSize size(LOWORD(rc), HIWORD(rc)); + + // We have to add space for the scrollbars ourselves, they're not taken + // into account by ListView_ApproximateViewRect(), at least not with + // commctrl32.dll v6. + const DWORD mswStyle = ::GetWindowLong(GetHwnd(), GWL_STYLE); + + if ( mswStyle & WS_HSCROLL ) + size.y += wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y); + if ( mswStyle & WS_VSCROLL ) + size.x += wxSystemSettings::GetMetric(wxSYS_VSCROLL_X); + + return size; +} + // ---------------------------------------------------------------------------- // Operations // ---------------------------------------------------------------------------- @@ -1452,7 +1475,7 @@ void wxListCtrl::InitEditControl(WXHWND hWnd) wxTextCtrl* wxListCtrl::EditLabel(long item, wxClassInfo* textControlClass) { - wxCHECK_MSG( textControlClass->IsKindOf(CLASSINFO(wxTextCtrl)), NULL, + wxCHECK_MSG( textControlClass->IsKindOf(wxCLASSINFO(wxTextCtrl)), NULL, "control used for label editing must be a wxTextCtrl" ); // ListView_EditLabel requires that the list has focus. @@ -1519,7 +1542,7 @@ long wxListCtrl::FindItem(long start, const wxString& str, bool partial) findInfo.flags = LVFI_STRING; if ( partial ) findInfo.flags |= LVFI_PARTIAL; - findInfo.psz = str.wx_str(); + findInfo.psz = str.t_str(); // ListView_FindItem() excludes the first item from search and to look // through all the items you need to start from -1 which is unnatural and @@ -1656,6 +1679,12 @@ long wxListCtrl::InsertItem(const wxListItem& info) { wxASSERT_MSG( !IsVirtual(), wxT("can't be used with virtual controls") ); + // In 2.8 it was possible to succeed inserting an item without initializing + // its ID as it defaulted to 0. This was however never supported and in 2.9 + // the ID is -1 by default and inserting it simply fails, but it might be + // not obvious why does it happen, so check it proactively. + wxASSERT_MSG( info.m_itemId != -1, wxS("Item ID must be set.") ); + LV_ITEM item; wxConvertToMSWListItem(this, info, item); item.mask &= ~LVIF_PARAM; @@ -1730,12 +1759,19 @@ long wxListCtrl::InsertItem(long index, const wxString& label, int imageIndex) } // For list view mode (only), inserts a column. -long wxListCtrl::InsertColumn(long col, const wxListItem& item) +long wxListCtrl::DoInsertColumn(long col, const wxListItem& item) { LV_COLUMN lvCol; wxConvertToMSWListCol(GetHwnd(), col, item, lvCol); - if ( !(lvCol.mask & LVCF_WIDTH) ) + // LVSCW_AUTOSIZE_USEHEADER is not supported when inserting new column, + // we'll deal with it below instead. Plain LVSCW_AUTOSIZE is not supported + // neither but it doesn't need any special handling as we use fixed value + // for it here, both because we can't do anything else (there are no items + // with values in this column to compute the size from yet) and for + // compatibility as wxLIST_AUTOSIZE == -1 and -1 as InsertColumn() width + // parameter used to mean "arbitrary fixed width". + if ( !(lvCol.mask & LVCF_WIDTH) || lvCol.cx < 0 ) { // always give some width to the new column: this one is compatible // with the generic version @@ -1744,35 +1780,23 @@ long wxListCtrl::InsertColumn(long col, const wxListItem& item) } long n = ListView_InsertColumn(GetHwnd(), col, &lvCol); - if ( n != -1 ) - { - m_colCount++; - } - else // failed to insert? + if ( n == -1 ) { wxLogDebug(wxT("Failed to insert the column '%s' into listview!"), lvCol.pszText); + return -1; } - return n; -} + m_colCount++; -long wxListCtrl::InsertColumn(long col, - const wxString& heading, - int format, - int width) -{ - wxListItem item; - item.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_FORMAT; - item.m_text = heading; - if ( width > -1 ) + // Now adjust the new column size. + if ( (item.GetMask() & wxLIST_MASK_WIDTH) && + (item.GetWidth() == wxLIST_AUTOSIZE_USEHEADER) ) { - item.m_mask |= wxLIST_MASK_WIDTH; - item.m_width = width; + SetColumnWidth(n, wxLIST_AUTOSIZE_USEHEADER); } - item.m_format = format; - return InsertColumn(col, item); + return n; } // scroll the control by the given number of pixels (exception: in list view, @@ -2637,10 +2661,21 @@ bool HandleSubItemPrepaint(LPNMLVCUSTOMDRAW pLVCD, HFONT hfont, int colCount) SelectInHDC selFont(hdc, hfont); // get the rectangle to paint - int subitem = colCount ? col + 1 : col; RECT rc; - wxGetListCtrlSubItemRect(hwndList, item, subitem, LVIR_BOUNDS, rc); - rc.left += 6; + wxGetListCtrlSubItemRect(hwndList, item, col, LVIR_BOUNDS, rc); + if ( !col && colCount > 1 ) + { + // ListView_GetSubItemRect() returns the entire item rect for 0th + // subitem while we really need just the part for this column + RECT rc2; + wxGetListCtrlSubItemRect(hwndList, item, 1, LVIR_BOUNDS, rc2); + rc.right = rc2.left; + rc.left += 4; + } + else // not first subitem + { + rc.left += 6; + } // get the image and text to draw wxChar text[512]; @@ -3255,7 +3290,7 @@ static void wxConvertToMSWListItem(const wxListCtrl *ctrl, else { // pszText is not const, hence the cast - lvItem.pszText = (wxChar *)info.m_text.wx_str(); + lvItem.pszText = wxMSW_CONV_LPTSTR(info.m_text); if ( lvItem.pszText ) lvItem.cchTextMax = info.m_text.length(); else @@ -3276,7 +3311,7 @@ static void wxConvertToMSWListCol(HWND hwndList, if ( item.m_mask & wxLIST_MASK_TEXT ) { lvCol.mask |= LVCF_TEXT; - lvCol.pszText = (wxChar *)item.m_text.wx_str(); // cast is safe + lvCol.pszText = wxMSW_CONV_LPTSTR(item.m_text); } if ( item.m_mask & wxLIST_MASK_FORMAT )