Add ellipsizeMode parameter to wxRenderNative::DrawItemText()
Instead of the default end ellipsize mode used in the native and generic implementation, allow specifying the mode with an additional parameter. Closes https://github.com/wxWidgets/wxWidgets/pull/97
This commit is contained in:
committed by
Vadim Zeitlin
parent
60a3d76045
commit
44bcc3a723
@@ -346,7 +346,8 @@ public:
|
|||||||
const wxString& text,
|
const wxString& text,
|
||||||
const wxRect& rect,
|
const wxRect& rect,
|
||||||
int align = wxALIGN_LEFT | wxALIGN_TOP,
|
int align = wxALIGN_LEFT | wxALIGN_TOP,
|
||||||
int flags = 0) = 0;
|
int flags = 0,
|
||||||
|
wxEllipsizeMode ellipsizeMode = wxELLIPSIZE_END) = 0;
|
||||||
|
|
||||||
// geometry functions
|
// geometry functions
|
||||||
// ------------------
|
// ------------------
|
||||||
@@ -548,8 +549,9 @@ public:
|
|||||||
const wxString& text,
|
const wxString& text,
|
||||||
const wxRect& rect,
|
const wxRect& rect,
|
||||||
int align = wxALIGN_LEFT | wxALIGN_TOP,
|
int align = wxALIGN_LEFT | wxALIGN_TOP,
|
||||||
int flags = 0)
|
int flags = 0,
|
||||||
{ m_rendererNative.DrawItemText(win, dc, text, rect, align, flags); }
|
wxEllipsizeMode ellipsizeMode = wxELLIPSIZE_END)
|
||||||
|
{ m_rendererNative.DrawItemText(win, dc, text, rect, align, flags, ellipsizeMode); }
|
||||||
|
|
||||||
virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win)
|
virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win)
|
||||||
{ return m_rendererNative.GetSplitterParams(win); }
|
{ return m_rendererNative.GetSplitterParams(win); }
|
||||||
|
@@ -430,7 +430,8 @@ public:
|
|||||||
const wxString& text,
|
const wxString& text,
|
||||||
const wxRect& rect,
|
const wxRect& rect,
|
||||||
int align = wxALIGN_LEFT | wxALIGN_TOP,
|
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.
|
Draw a blank push button that looks very similar to wxButton.
|
||||||
|
@@ -981,20 +981,6 @@ wxDataViewCustomRendererBase::RenderText(const wxString& text,
|
|||||||
rectText.x += xoffset;
|
rectText.x += xoffset;
|
||||||
rectText.width -= 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;
|
int flags = 0;
|
||||||
if ( state & wxDATAVIEW_CELL_SELECTED )
|
if ( state & wxDATAVIEW_CELL_SELECTED )
|
||||||
flags |= wxCONTROL_SELECTED | wxCONTROL_FOCUSED;
|
flags |= wxCONTROL_SELECTED | wxCONTROL_FOCUSED;
|
||||||
@@ -1005,10 +991,11 @@ wxDataViewCustomRendererBase::RenderText(const wxString& text,
|
|||||||
wxRendererNative::Get().DrawItemText(
|
wxRendererNative::Get().DrawItemText(
|
||||||
GetOwner()->GetOwner(),
|
GetOwner()->GetOwner(),
|
||||||
*dc,
|
*dc,
|
||||||
ellipsizedText.empty() ? text : ellipsizedText,
|
text,
|
||||||
rectText,
|
rectText,
|
||||||
GetEffectiveAlignment(),
|
GetEffectiveAlignment(),
|
||||||
flags);
|
flags,
|
||||||
|
GetEllipsizeMode());
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxDataViewCustomRendererBase::SetEnabled(bool enabled)
|
void wxDataViewCustomRendererBase::SetEnabled(bool enabled)
|
||||||
|
@@ -150,7 +150,8 @@ public:
|
|||||||
const wxString& text,
|
const wxString& text,
|
||||||
const wxRect& rect,
|
const wxRect& rect,
|
||||||
int align = wxALIGN_LEFT | wxALIGN_TOP,
|
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;
|
virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win) wxOVERRIDE;
|
||||||
|
|
||||||
@@ -888,7 +889,8 @@ wxRendererGeneric::DrawItemText(wxWindow* win,
|
|||||||
const wxString& text,
|
const wxString& text,
|
||||||
const wxRect& rect,
|
const wxRect& rect,
|
||||||
int align,
|
int align,
|
||||||
int flags)
|
int flags,
|
||||||
|
wxEllipsizeMode ellipsizeMode)
|
||||||
{
|
{
|
||||||
// Determine text color
|
// Determine text color
|
||||||
wxColour textColour;
|
wxColour textColour;
|
||||||
@@ -913,7 +915,7 @@ wxRendererGeneric::DrawItemText(wxWindow* win,
|
|||||||
}
|
}
|
||||||
|
|
||||||
const wxString paintText = wxControl::Ellipsize(text, dc,
|
const wxString paintText = wxControl::Ellipsize(text, dc,
|
||||||
wxELLIPSIZE_END,
|
ellipsizeMode,
|
||||||
rect.GetWidth());
|
rect.GetWidth());
|
||||||
|
|
||||||
// Draw text
|
// Draw text
|
||||||
|
@@ -26,6 +26,7 @@
|
|||||||
#ifndef WX_PRECOMP
|
#ifndef WX_PRECOMP
|
||||||
#include "wx/string.h"
|
#include "wx/string.h"
|
||||||
#include "wx/window.h"
|
#include "wx/window.h"
|
||||||
|
#include "wx/control.h" // for wxControl::Ellipsize()
|
||||||
#include "wx/dc.h"
|
#include "wx/dc.h"
|
||||||
#include "wx/settings.h"
|
#include "wx/settings.h"
|
||||||
#endif //WX_PRECOMP
|
#endif //WX_PRECOMP
|
||||||
@@ -338,7 +339,8 @@ public:
|
|||||||
const wxString& text,
|
const wxString& text,
|
||||||
const wxRect& rect,
|
const wxRect& rect,
|
||||||
int align = wxALIGN_LEFT | wxALIGN_TOP,
|
int align = wxALIGN_LEFT | wxALIGN_TOP,
|
||||||
int flags = 0);
|
int flags = 0,
|
||||||
|
wxEllipsizeMode ellipsizeMode = wxELLIPSIZE_END);
|
||||||
|
|
||||||
virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win);
|
virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win);
|
||||||
|
|
||||||
@@ -970,7 +972,8 @@ void wxRendererXP::DrawItemText(wxWindow* win,
|
|||||||
const wxString& text,
|
const wxString& text,
|
||||||
const wxRect& rect,
|
const wxRect& rect,
|
||||||
int align,
|
int align,
|
||||||
int flags)
|
int flags,
|
||||||
|
wxEllipsizeMode ellipsizeMode)
|
||||||
{
|
{
|
||||||
wxUxThemeHandle hTheme(win, L"LISTVIEW");
|
wxUxThemeHandle hTheme(win, L"LISTVIEW");
|
||||||
|
|
||||||
@@ -999,7 +1002,7 @@ void wxRendererXP::DrawItemText(wxWindow* win,
|
|||||||
textOpts.crText = wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT).GetPixel();
|
textOpts.crText = wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT).GetPixel();
|
||||||
}
|
}
|
||||||
|
|
||||||
DWORD textFlags = DT_NOPREFIX | DT_END_ELLIPSIS;
|
DWORD textFlags = DT_NOPREFIX;
|
||||||
if ( align & wxALIGN_CENTER_HORIZONTAL )
|
if ( align & wxALIGN_CENTER_HORIZONTAL )
|
||||||
textFlags |= DT_CENTER;
|
textFlags |= DT_CENTER;
|
||||||
else if ( align & wxALIGN_RIGHT )
|
else if ( align & wxALIGN_RIGHT )
|
||||||
@@ -1014,12 +1017,37 @@ void wxRendererXP::DrawItemText(wxWindow* win,
|
|||||||
else
|
else
|
||||||
textFlags |= DT_TOP;
|
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,
|
te->DrawThemeTextEx(hTheme, dc.GetHDC(), LVP_LISTITEM, itemState,
|
||||||
text.wchar_str(), -1, textFlags, &rc, &textOpts);
|
drawText->wchar_str(), -1, textFlags, &rc, &textOpts);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_rendererNative.DrawItemText(win, dc, text, rect, align, flags);
|
m_rendererNative.DrawItemText(win, dc, text, rect, align, flags, ellipsizeMode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user