diff --git a/include/wx/renderer.h b/include/wx/renderer.h index d854007e59..3fe946139d 100644 --- a/include/wx/renderer.h +++ b/include/wx/renderer.h @@ -346,7 +346,8 @@ public: const wxString& text, const wxRect& rect, int align = wxALIGN_LEFT | wxALIGN_TOP, - int flags = 0) = 0; + int flags = 0, + wxEllipsizeMode ellipsizeMode = wxELLIPSIZE_END) = 0; // geometry functions // ------------------ @@ -548,8 +549,9 @@ public: const wxString& text, const wxRect& rect, int align = wxALIGN_LEFT | wxALIGN_TOP, - int flags = 0) - { m_rendererNative.DrawItemText(win, dc, text, rect, align, flags); } + int flags = 0, + wxEllipsizeMode ellipsizeMode = wxELLIPSIZE_END) + { m_rendererNative.DrawItemText(win, dc, text, rect, align, flags, ellipsizeMode); } virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win) { return m_rendererNative.GetSplitterParams(win); } diff --git a/interface/wx/renderer.h b/interface/wx/renderer.h index 3ee7e7ae3f..ee71ee992b 100644 --- a/interface/wx/renderer.h +++ b/interface/wx/renderer.h @@ -430,7 +430,8 @@ public: const wxString& text, const wxRect& rect, int align = wxALIGN_LEFT | wxALIGN_TOP, - int flags = 0) = 0; + int flags = 0, + wxEllipsizeMode ellipsizeMode = wxELLIPSIZE_END) = 0; /** Draw a blank push button that looks very similar to wxButton. diff --git a/src/common/datavcmn.cpp b/src/common/datavcmn.cpp index 536e7ae2ea..d701b88253 100644 --- a/src/common/datavcmn.cpp +++ b/src/common/datavcmn.cpp @@ -981,20 +981,6 @@ wxDataViewCustomRendererBase::RenderText(const wxString& text, rectText.x += xoffset; rectText.width -= xoffset; - // check if we want to ellipsize the text if it doesn't fit - wxString ellipsizedText; - if ( GetEllipsizeMode() != wxELLIPSIZE_NONE ) - { - ellipsizedText = wxControl::Ellipsize - ( - text, - *dc, - GetEllipsizeMode(), - rectText.width, - wxELLIPSIZE_FLAGS_NONE - ); - } - int flags = 0; if ( state & wxDATAVIEW_CELL_SELECTED ) flags |= wxCONTROL_SELECTED | wxCONTROL_FOCUSED; @@ -1005,10 +991,11 @@ wxDataViewCustomRendererBase::RenderText(const wxString& text, wxRendererNative::Get().DrawItemText( GetOwner()->GetOwner(), *dc, - ellipsizedText.empty() ? text : ellipsizedText, + text, rectText, GetEffectiveAlignment(), - flags); + flags, + GetEllipsizeMode()); } void wxDataViewCustomRendererBase::SetEnabled(bool enabled) diff --git a/src/generic/renderg.cpp b/src/generic/renderg.cpp index 96f3ac40d9..b078566e17 100644 --- a/src/generic/renderg.cpp +++ b/src/generic/renderg.cpp @@ -150,7 +150,8 @@ public: const wxString& text, const wxRect& rect, int align = wxALIGN_LEFT | wxALIGN_TOP, - int flags = 0) wxOVERRIDE; + int flags = 0, + wxEllipsizeMode ellipsizeMode = wxELLIPSIZE_END) wxOVERRIDE; virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win) wxOVERRIDE; @@ -888,7 +889,8 @@ wxRendererGeneric::DrawItemText(wxWindow* win, const wxString& text, const wxRect& rect, int align, - int flags) + int flags, + wxEllipsizeMode ellipsizeMode) { // Determine text color wxColour textColour; @@ -913,7 +915,7 @@ wxRendererGeneric::DrawItemText(wxWindow* win, } const wxString paintText = wxControl::Ellipsize(text, dc, - wxELLIPSIZE_END, + ellipsizeMode, rect.GetWidth()); // Draw text diff --git a/src/msw/renderer.cpp b/src/msw/renderer.cpp index a9ab26d01b..b297a7c8e1 100644 --- a/src/msw/renderer.cpp +++ b/src/msw/renderer.cpp @@ -26,6 +26,7 @@ #ifndef WX_PRECOMP #include "wx/string.h" #include "wx/window.h" + #include "wx/control.h" // for wxControl::Ellipsize() #include "wx/dc.h" #include "wx/settings.h" #endif //WX_PRECOMP @@ -338,7 +339,8 @@ public: const wxString& text, const wxRect& rect, int align = wxALIGN_LEFT | wxALIGN_TOP, - int flags = 0); + int flags = 0, + wxEllipsizeMode ellipsizeMode = wxELLIPSIZE_END); virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win); @@ -970,7 +972,8 @@ void wxRendererXP::DrawItemText(wxWindow* win, const wxString& text, const wxRect& rect, int align, - int flags) + int flags, + wxEllipsizeMode ellipsizeMode) { wxUxThemeHandle hTheme(win, L"LISTVIEW"); @@ -999,7 +1002,7 @@ void wxRendererXP::DrawItemText(wxWindow* win, textOpts.crText = wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT).GetPixel(); } - DWORD textFlags = DT_NOPREFIX | DT_END_ELLIPSIS; + DWORD textFlags = DT_NOPREFIX; if ( align & wxALIGN_CENTER_HORIZONTAL ) textFlags |= DT_CENTER; else if ( align & wxALIGN_RIGHT ) @@ -1014,12 +1017,37 @@ void wxRendererXP::DrawItemText(wxWindow* win, else textFlags |= DT_TOP; + const wxString* drawText = &text; + wxString ellipsizedText; + switch ( ellipsizeMode ) + { + case wxELLIPSIZE_NONE: + // no flag required + break; + + case wxELLIPSIZE_START: + case wxELLIPSIZE_MIDDLE: + // no native support for this ellipsize modes, use wxWidgets + // implementation (may not be 100% accurate because per + // definition the theme defines the font but should be close + // enough with current windows themes) + drawText = &ellipsizedText; + ellipsizedText = wxControl::Ellipsize(text, dc, ellipsizeMode, + rect.width, + wxELLIPSIZE_FLAGS_NONE); + break; + + case wxELLIPSIZE_END: + textFlags |= DT_END_ELLIPSIS; + break; + } + te->DrawThemeTextEx(hTheme, dc.GetHDC(), LVP_LISTITEM, itemState, - text.wchar_str(), -1, textFlags, &rc, &textOpts); + drawText->wchar_str(), -1, textFlags, &rc, &textOpts); } else { - m_rendererNative.DrawItemText(win, dc, text, rect, align, flags); + m_rendererNative.DrawItemText(win, dc, text, rect, align, flags, ellipsizeMode); } }