X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/94e0018723919fe2ca2f5b5f0a42804c16dbf3a1..be74a2a21a491f5d0ec6a333b2fdc4bedb578eaa:/src/msw/listctrl.cpp diff --git a/src/msw/listctrl.cpp b/src/msw/listctrl.cpp index 1e1c9a722c..8d0bead333 100644 --- a/src/msw/listctrl.cpp +++ b/src/msw/listctrl.cpp @@ -226,8 +226,9 @@ public: wxDECLARE_NO_COPY_CLASS(wxMSWListItemData); }; -BEGIN_EVENT_TABLE(wxListCtrl, wxControl) +BEGIN_EVENT_TABLE(wxListCtrl, wxListCtrlBase) EVT_PAINT(wxListCtrl::OnPaint) + EVT_CHAR_HOOK(wxListCtrl::OnCharHook) END_EVENT_TABLE() // ============================================================================ @@ -308,7 +309,7 @@ void wxListCtrl::MSWSetExListStyles() WXDWORD wxListCtrl::MSWGetStyle(long style, WXDWORD *exstyle) const { - WXDWORD wstyle = wxControl::MSWGetStyle(style, exstyle); + WXDWORD wstyle = wxListCtrlBase::MSWGetStyle(style, exstyle); wstyle |= LVS_SHAREIMAGELISTS | LVS_SHOWSELALWAYS; @@ -477,7 +478,7 @@ void wxListCtrl::SetWindowStyleFlag(long flag) { if ( flag != m_windowStyle ) { - wxControl::SetWindowStyleFlag(flag); + wxListCtrlBase::SetWindowStyleFlag(flag); UpdateStyle(); @@ -1490,21 +1491,15 @@ bool wxListCtrl::EndEditLabel(bool cancel) if ( !hwnd ) return false; - // Newer versions of Windows have a special message for cancelling editing, - // use it if available. -#ifdef ListView_CancelEditLabel - if ( cancel && (wxApp::GetComCtl32Version() >= 600) ) - { - ListView_CancelEditLabel(GetHwnd()); - } - else -#endif // ListView_CancelEditLabel - { - // We shouldn't destroy the control ourselves according to MSDN, which - // proposes WM_CANCELMODE to do this, but it doesn't seem to work so - // emulate the corresponding user action instead. - ::SendMessage(hwnd, WM_KEYDOWN, cancel ? VK_ESCAPE : VK_RETURN, 0); - } + // Newer versions of Windows have a special ListView_CancelEditLabel() + // message for cancelling editing but it, rather counter-intuitively, keeps + // the last text entered in the dialog while cancelling as we do it below + // restores the original text which is the more expected behaviour. + + // We shouldn't destroy the control ourselves according to MSDN, which + // proposes WM_CANCELMODE to do this, but it doesn't seem to work so + // emulate the corresponding user action instead. + ::SendMessage(hwnd, WM_KEYDOWN, cancel ? VK_ESCAPE : VK_RETURN, 0); return true; } @@ -1735,12 +1730,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 @@ -1749,35 +1751,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, @@ -1867,7 +1857,7 @@ bool wxListCtrl::MSWShouldPreProcessMessage(WXMSG* msg) return false; } } - return wxControl::MSWShouldPreProcessMessage(msg); + return wxListCtrlBase::MSWShouldPreProcessMessage(msg); } bool wxListCtrl::MSWCommand(WXUINT cmd, WXWORD id_) @@ -1905,9 +1895,8 @@ int WXDLLIMPEXP_CORE wxMSWGetColumnClicked(NMHDR *nmhdr, POINT *ptClick) } else #endif //__WXWINCE__ - if ( !::GetCursorPos(ptClick) ) { - wxLogLastError(wxT("GetCursorPos")); + wxGetCursorPosMSW(ptClick); } // we need to use listctrl coordinates for the event point so this is what @@ -2053,7 +2042,7 @@ bool wxListCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) } if ( ignore ) - return wxControl::MSWOnNotify(idCtrl, lParam, result); + return wxListCtrlBase::MSWOnNotify(idCtrl, lParam, result); } else #endif // defined(HDN_BEGINTRACKA) @@ -2281,7 +2270,7 @@ bool wxListCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) case NM_DBLCLK: // if the user processes it in wxEVT_COMMAND_LEFT_CLICK(), don't do // anything else - if ( wxControl::MSWOnNotify(idCtrl, lParam, result) ) + if ( wxListCtrlBase::MSWOnNotify(idCtrl, lParam, result) ) { return true; } @@ -2306,7 +2295,7 @@ bool wxListCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) case NM_RCLICK: // if the user processes it in wxEVT_COMMAND_RIGHT_CLICK(), // don't do anything else - if ( wxControl::MSWOnNotify(idCtrl, lParam, result) ) + if ( wxListCtrlBase::MSWOnNotify(idCtrl, lParam, result) ) { return true; } @@ -2323,7 +2312,7 @@ bool wxListCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) else #endif //__WXWINCE__ { - ::GetCursorPos(&(lvhti.pt)); + wxGetCursorPosMSW(&(lvhti.pt)); } ::ScreenToClient(GetHwnd(), &lvhti.pt); @@ -2519,7 +2508,7 @@ bool wxListCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) } if ( !processed ) - return wxControl::MSWOnNotify(idCtrl, lParam, result); + return wxListCtrlBase::MSWOnNotify(idCtrl, lParam, result); } else { @@ -2534,7 +2523,11 @@ bool wxListCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) // fill in the item before passing it to the event handler if we do have a // valid item index and haven't filled it yet (e.g. for LVN_ITEMCHANGED) - if ( event.m_itemIndex != -1 && !event.m_item.GetMask() ) + // and we're not using a virtual control as in this case the program + // already has the data anyhow and we don't want to call GetItem() for + // potentially many items + if ( event.m_itemIndex != -1 && !event.m_item.GetMask() + && !IsVirtual() ) { wxListItem& item = event.m_item; @@ -2905,7 +2898,7 @@ void wxListCtrl::OnPaint(wxPaintEvent& event) wxPaintDC dc(this); - wxControl::OnPaint(event); + wxListCtrlBase::OnPaint(event); // Reset the device origin since it may have been set dc.SetDeviceOrigin(0, 0); @@ -2980,6 +2973,27 @@ void wxListCtrl::OnPaint(wxPaintEvent& event) } } +void wxListCtrl::OnCharHook(wxKeyEvent& event) +{ + if ( GetEditControl() ) + { + // We need to ensure that Escape is not stolen from the in-place editor + // by the containing dialog. + // + // Notice that we don't have to care about Enter key here as we return + // false from MSWShouldPreProcessMessage() for it. + if ( event.GetKeyCode() == WXK_ESCAPE ) + { + EndEditLabel(true /* cancel */); + + // Don't call Skip() below. + return; + } + } + + event.Skip(); +} + WXLRESULT wxListCtrl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) { @@ -3003,7 +3017,7 @@ wxListCtrl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) //else: break } - return wxControl::MSWWindowProc(nMsg, wParam, lParam); + return wxListCtrlBase::MSWWindowProc(nMsg, wParam, lParam); } // ----------------------------------------------------------------------------