Make wxPG_TOOLTIPS work for >2 columns too

This commit is contained in:
Pavel Tyunin
2020-09-15 15:13:34 +03:00
committed by Artur Wieczorek
parent 7d83c6cfe0
commit 47d8299c70
2 changed files with 23 additions and 38 deletions

View File

@@ -1591,11 +1591,12 @@ protected:
// 0 = not dragging, 1 = drag just started, 2 = drag in progress // 0 = not dragging, 1 = drag just started, 2 = drag in progress
unsigned char m_dragStatus; unsigned char m_dragStatus;
#if WXWIN_COMPATIBILITY_3_0
// Unused variable.
// 0 = margin, 1 = label, 2 = value. // 0 = margin, 1 = label, 2 = value.
unsigned char m_mouseSide; unsigned char m_mouseSide;
// True when editor control is focused. // True when editor control is focused.
#if WXWIN_COMPATIBILITY_3_0
unsigned char m_editorFocused; unsigned char m_editorFocused;
#else #else
bool m_editorFocused; bool m_editorFocused;
@@ -1634,8 +1635,8 @@ protected:
int m_clearThisMany; int m_clearThisMany;
#endif #endif
// Mouse is hovering over this column (index) // Mouse is hovering over this column (index), -1 for margin
unsigned int m_colHover; int m_colHover;
// pointer to property that has mouse hovering // pointer to property that has mouse hovering
wxPGProperty* m_propHover; wxPGProperty* m_propHover;

View File

@@ -355,7 +355,6 @@ void wxPropertyGrid::Init1()
m_inOnValidationFailure = false; m_inOnValidationFailure = false;
m_permanentValidationFailureBehavior = wxPG_VFB_DEFAULT; m_permanentValidationFailureBehavior = wxPG_VFB_DEFAULT;
m_dragStatus = 0; m_dragStatus = 0;
m_mouseSide = 16;
m_editorFocused = false; m_editorFocused = false;
// Set up default unspecified value 'colour' // Set up default unspecified value 'colour'
@@ -5003,6 +5002,10 @@ bool wxPropertyGrid::HandleMouseMove( int x, unsigned int y,
int splitterHitOffset; int splitterHitOffset;
int columnHit = state->HitTestH( x, &splitterHit, &splitterHitOffset ); int columnHit = state->HitTestH( x, &splitterHit, &splitterHitOffset );
#if wxUSE_TOOLTIPS
wxPGProperty* prevHover = m_propHover;
int prevCol = m_colHover;
#endif
m_colHover = columnHit; m_colHover = columnHit;
if ( m_dragStatus > 0 ) if ( m_dragStatus > 0 )
@@ -5042,10 +5045,6 @@ bool wxPropertyGrid::HandleMouseMove( int x, unsigned int y,
int ih = m_lineHeight; int ih = m_lineHeight;
int sy = y; int sy = y;
#if wxUSE_TOOLTIPS
wxPGProperty* prevHover = m_propHover;
unsigned char prevSide = m_mouseSide;
#endif
int curPropHoverY = y - (y % ih); int curPropHoverY = y - (y % ih);
// On which item it hovers // On which item it hovers
@@ -5064,20 +5063,13 @@ bool wxPropertyGrid::HandleMouseMove( int x, unsigned int y,
} }
#if wxUSE_TOOLTIPS #if wxUSE_TOOLTIPS
// Store which side we are on
m_mouseSide = 0;
if ( columnHit == 1 )
m_mouseSide = 2;
else if ( columnHit == 0 )
m_mouseSide = 1;
// //
// If tooltips are enabled, show label or value as a tip // If tooltips are enabled, show label or value as a tip
// in case it doesn't otherwise show in full length. // in case it doesn't otherwise show in full length.
// //
if ( m_windowStyle & wxPG_TOOLTIPS ) if ( m_windowStyle & wxPG_TOOLTIPS )
{ {
if ( m_propHover != prevHover || prevSide != m_mouseSide ) if ( m_propHover != prevHover || prevCol != m_colHover )
{ {
if ( m_propHover && !m_propHover->IsCategory() ) if ( m_propHover && !m_propHover->IsCategory() )
{ {
@@ -5089,43 +5081,35 @@ bool wxPropertyGrid::HandleMouseMove( int x, unsigned int y,
SetToolTip(tipString); SetToolTip(tipString);
} }
else else if ( m_colHover >= 0 && m_colHover < (int)m_pState->GetColumnCount())
{ {
// Show cropped value string as a tooltip // Show cropped value string as a tooltip
wxString tipString; wxString tipString;
int space = 0; m_propHover->GetDisplayInfo(m_colHover, -1, 0, &tipString, (wxPGCell*)NULL);
int space = m_pState->GetColumnWidth(m_colHover);
if ( m_mouseSide == 1 ) if ( m_colHover == 0 )
{ {
tipString = m_propHover->GetLabel();
space = m_pState->GetColumnWidth(0);
if ( !(m_windowStyle & wxPG_HIDE_CATEGORIES) || m_propHover->GetParent() != m_pState->DoGetRoot() ) if ( !(m_windowStyle & wxPG_HIDE_CATEGORIES) || m_propHover->GetParent() != m_pState->DoGetRoot() )
space -= (m_propHover->GetDepth()-1)*m_subgroup_extramargin; space -= (m_propHover->GetDepth()-1)*m_subgroup_extramargin;
} }
else if ( m_mouseSide == 2 ) else if ( m_colHover == 1 )
{ {
tipString = m_propHover->GetDisplayedString();
space = m_pState->GetColumnWidth(1);
if ( m_propHover->HasFlag(wxPG_PROP_CUSTOMIMAGE) ) if ( m_propHover->HasFlag(wxPG_PROP_CUSTOMIMAGE) )
space -= wxPG_CUSTOM_IMAGE_WIDTH + space -= wxPG_CUSTOM_IMAGE_WIDTH +
wxCC_CUSTOM_IMAGE_MARGIN1 + wxCC_CUSTOM_IMAGE_MARGIN1 +
wxCC_CUSTOM_IMAGE_MARGIN2; wxCC_CUSTOM_IMAGE_MARGIN2;
} }
if ( space ) space -= (wxPG_XBEFORETEXT + 1);
{ int tw, th;
space -= (wxPG_XBEFORETEXT + 1); GetTextExtent( tipString, &tw, &th, 0, 0 );
int tw, th; if ( tw > space )
GetTextExtent( tipString, &tw, &th, 0, 0 ); SetToolTip( tipString );
if ( tw > space ) }
SetToolTip( tipString ); else
} {
else SetToolTip(wxEmptyString);
{
SetToolTip(wxEmptyString);
}
} }
} }
else else