fixes redraw bug which was leaving a horizontal strip under the tree item

after it was unselected (in wxGTK)


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@158 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
1998-06-29 16:23:41 +00:00
parent a5f81d8c07
commit 29d87bba53

View File

@@ -5,7 +5,7 @@
// Created: 01/02/97 // Created: 01/02/97
// Id: // Id:
// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
// Licence: wxWindows licence // Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__ #ifdef __GNUG__
@@ -69,7 +69,7 @@ wxGenericTreeItem::wxGenericTreeItem( wxGenericTreeItem *parent, const wxTreeIte
void wxGenericTreeItem::SetItem( const wxTreeItem &item, wxDC *dc ) void wxGenericTreeItem::SetItem( const wxTreeItem &item, wxDC *dc )
{ {
if ((item.m_mask & wxTREE_MASK_HANDLE) == wxTREE_MASK_HANDLE) if ((item.m_mask & wxTREE_MASK_HANDLE) == wxTREE_MASK_HANDLE)
m_itemId = item.m_itemId; m_itemId = item.m_itemId;
if ((item.m_mask & wxTREE_MASK_STATE) == wxTREE_MASK_STATE) if ((item.m_mask & wxTREE_MASK_STATE) == wxTREE_MASK_STATE)
m_state = item.m_state; m_state = item.m_state;
@@ -212,8 +212,7 @@ long wxGenericTreeItem::HitTest( const wxPoint& point, int &flags )
(point.x < m_xCross+5) && (point.x < m_xCross+5) &&
(point.y > m_yCross-5) && (point.y > m_yCross-5) &&
(point.y < m_yCross+5) && (point.y < m_yCross+5) &&
(m_hasChildren) (m_hasChildren))
)
{ {
flags = wxTREE_HITTEST_ONITEMBUTTON; flags = wxTREE_HITTEST_ONITEMBUTTON;
return m_itemId; return m_itemId;
@@ -408,25 +407,25 @@ long wxTreeCtrl::InsertItem( const long parent, const wxString& label, const int
item.m_selectedImage = selImage; item.m_selectedImage = selImage;
item.m_mask |= wxTREE_MASK_SELECTED_IMAGE; item.m_mask |= wxTREE_MASK_SELECTED_IMAGE;
}; };
wxClientDC dc(this); wxClientDC dc(this);
wxGenericTreeItem *new_child = new wxGenericTreeItem( p, item, &dc ); wxGenericTreeItem *new_child = new wxGenericTreeItem( p, item, &dc );
if (p) if (p)
p->AddChild( new_child ); p->AddChild( new_child );
else else
m_anchor = new_child; m_anchor = new_child;
if (p) if (p)
{ {
CalculatePositions(); CalculatePositions();
int ch = 0; int ch = 0;
GetClientSize( NULL, &ch ); GetClientSize( NULL, &ch );
wxRectangle rect; wxRectangle rect;
rect.x = 0; rect.y = 0; rect.x = 0; rect.y = 0;
rect.width = 10000; rect.height = ch; rect.width = 10000; rect.height = ch;
PrepareDC( dc ); PrepareDC( dc );
if (p->m_children.Number() == 1) if (p->m_children.Number() == 1)
{ {
@@ -438,23 +437,23 @@ long wxTreeCtrl::InsertItem( const long parent, const wxString& label, const int
wxGenericTreeItem* last_child = (wxGenericTreeItem*)node->Data(); wxGenericTreeItem* last_child = (wxGenericTreeItem*)node->Data();
rect.y = dc.LogicalToDeviceY( last_child->m_y ); rect.y = dc.LogicalToDeviceY( last_child->m_y );
}; };
long doX = 0; long doX = 0;
long doY = 0; long doY = 0;
dc.GetDeviceOrigin( &doX, &doY ); dc.GetDeviceOrigin( &doX, &doY );
rect.height = ch-rect.y-doY; rect.height = ch-rect.y-doY;
AdjustMyScrollbars(); AdjustMyScrollbars();
if (rect.height > 0) Refresh( FALSE, &rect); if (rect.height > 0) Refresh( FALSE, &rect);
} }
else else
{ {
AdjustMyScrollbars(); AdjustMyScrollbars();
Refresh(); Refresh();
}; };
return m_lastId; return m_lastId;
}; };
@@ -487,25 +486,25 @@ long wxTreeCtrl::InsertItem( const long parent, wxTreeItem &info, const long WXU
{ {
ret = info.m_itemId; ret = info.m_itemId;
}; };
wxClientDC dc(this); wxClientDC dc(this);
wxGenericTreeItem *new_child = new wxGenericTreeItem( p, info, &dc ); wxGenericTreeItem *new_child = new wxGenericTreeItem( p, info, &dc );
if (p) if (p)
p->AddChild( new_child ); p->AddChild( new_child );
else else
m_anchor = new_child; m_anchor = new_child;
if (p) if (p)
{ {
CalculatePositions(); CalculatePositions();
int ch = 0; int ch = 0;
GetClientSize( NULL, &ch ); GetClientSize( NULL, &ch );
wxRectangle rect; wxRectangle rect;
rect.x = 0; rect.y = 0; rect.x = 0; rect.y = 0;
rect.width = 10000; rect.height = ch; rect.width = 10000; rect.height = ch;
PrepareDC( dc ); PrepareDC( dc );
if (p->m_children.Number() == 1) if (p->m_children.Number() == 1)
{ {
@@ -517,23 +516,23 @@ long wxTreeCtrl::InsertItem( const long parent, wxTreeItem &info, const long WXU
wxGenericTreeItem* last_child = (wxGenericTreeItem*)node->Data(); wxGenericTreeItem* last_child = (wxGenericTreeItem*)node->Data();
rect.y = dc.LogicalToDeviceY( last_child->m_y ); rect.y = dc.LogicalToDeviceY( last_child->m_y );
}; };
long doX = 0; long doX = 0;
long doY = 0; long doY = 0;
dc.GetDeviceOrigin( &doX, &doY ); dc.GetDeviceOrigin( &doX, &doY );
rect.height = ch-rect.y-doY; rect.height = ch-rect.y-doY;
AdjustMyScrollbars(); AdjustMyScrollbars();
if (rect.height > 0) Refresh( FALSE, &rect); if (rect.height > 0) Refresh( FALSE, &rect);
} }
else else
{ {
AdjustMyScrollbars(); AdjustMyScrollbars();
Refresh(); Refresh();
}; };
info.m_mask = oldMask; info.m_mask = oldMask;
return ret; return ret;
}; };
@@ -557,10 +556,10 @@ bool wxTreeCtrl::ExpandItem( const long item, const int action )
{ {
wxGenericTreeItem *child = (wxGenericTreeItem*)node->Data(); wxGenericTreeItem *child = (wxGenericTreeItem*)node->Data();
child->SendDelete( this ); child->SendDelete( this );
delete node; delete node;
node = i->m_children.First(); node = i->m_children.First();
}; };
int cw = 0; int cw = 0;
int ch = 0; int ch = 0;
GetClientSize( &cw, &ch ); GetClientSize( &cw, &ch );
@@ -570,12 +569,12 @@ bool wxTreeCtrl::ExpandItem( const long item, const int action )
wxClientDC dc(this); wxClientDC dc(this);
PrepareDC(dc); PrepareDC(dc);
rect.y = dc.LogicalToDeviceY( i->m_y ); rect.y = dc.LogicalToDeviceY( i->m_y );
long doY = 0; long doY = 0;
dc.GetDeviceOrigin( NULL, &doY ); dc.GetDeviceOrigin( NULL, &doY );
rect.height = ch-rect.y-doY; rect.height = ch-rect.y-doY;
Refresh( TRUE, &rect ); Refresh( TRUE, &rect );
AdjustMyScrollbars(); AdjustMyScrollbars();
break; break;
}; };
@@ -724,29 +723,31 @@ void wxTreeCtrl::PaintLevel( wxGenericTreeItem *item, wxPaintDC &dc, int level,
{ {
wxGenericTreeItem *child = (wxGenericTreeItem *)node->Data(); wxGenericTreeItem *child = (wxGenericTreeItem *)node->Data();
dc.SetPen( m_dottedPen ); dc.SetPen( m_dottedPen );
child->SetCross( horizX+15, y ); child->SetCross( horizX+15, y );
if (!node->Next()) if (!node->Next())
{ {
if (level != 0) oldY -= (m_lineHeight-5); if (level != 0) oldY -= (m_lineHeight-5);
dc.DrawLine( horizX, oldY, horizX, y ); dc.DrawLine( horizX, oldY, horizX, y );
}; };
child->m_x = horizX+33; child->m_x = horizX+33;
child->m_y = y-m_lineHeight/3; child->m_y = y-m_lineHeight/3;
child->m_height = m_lineHeight; child->m_height = m_lineHeight;
if (IsExposed( 0, child->m_y-2, 10000, m_lineHeight+4 )) if (IsExposed( 0, child->m_y-2, 10000, m_lineHeight+4 ))
{ {
int startX,endX; int startX = horizX,
if ((node->Previous()) || (level != 0)) endX = horizX + 10;
startX = horizX; else startX = horizX-10;
if (child->HasChildren()) if (!(node->Previous()) && (level == 0))
endX = horizX+10; else endX = horizX+30; startX -= 10;
if (!child->HasChildren())
endX += 20;
dc.DrawLine( startX, y, endX, y ); dc.DrawLine( startX, y, endX, y );
if (child->HasChildren()) if (child->HasChildren())
{ {
dc.DrawLine( horizX+20, y, horizX+30, y ); dc.DrawLine( horizX+20, y, horizX+30, y );
dc.SetPen( *wxGREY_PEN ); dc.SetPen( *wxGREY_PEN );
@@ -756,34 +757,42 @@ void wxTreeCtrl::PaintLevel( wxGenericTreeItem *item, wxPaintDC &dc, int level,
if (child->HasPlus()) if (child->HasPlus())
dc.DrawLine( horizX+15, y-2, horizX+15, y+2 ); dc.DrawLine( horizX+15, y-2, horizX+15, y+2 );
}; };
if (child->HasHilight())
{
dc.SetTextForeground( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT ) );
dc.SetBrush( *m_hilightBrush );
if (m_hasFocus)
dc.SetPen( wxBLACK_PEN );
else
dc.SetPen( wxTRANSPARENT_PEN );
long tw = 0;
long th = 0;
dc.GetTextExtent( child->m_text, &tw, &th );
dc.DrawRectangle( child->m_x-2, child->m_y-2, tw+4, th+4 );
};
dc.DrawText( child->m_text, child->m_x, child->m_y );
if (child->HasHilight()) if (child->HasHilight())
{ {
dc.SetTextForeground( *wxBLACK ); dc.SetTextForeground( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT ) );
dc.SetBrush( *wxWHITE_BRUSH ); #if 0 // VZ: this code leaves horizontal stripes when item is unselected
dc.SetPen( *wxBLACK_PEN ); dc.SetBrush( *m_hilightBrush );
}; if (m_hasFocus)
dc.SetPen( wxBLACK_PEN );
else
dc.SetPen( wxTRANSPARENT_PEN );
long tw, th;
dc.GetTextExtent( child->m_text, &tw, &th );
dc.DrawRectangle( child->m_x-2, child->m_y-2, tw+4, th+4 );
#else
int modeOld = dc.GetBackgroundMode();
dc.SetTextBackground( *wxBLACK );
dc.SetBackgroundMode(wxSOLID);
#endif // 0
dc.DrawText( child->m_text, child->m_x, child->m_y );
#if 0 // VZ: same as above
dc.SetPen( *wxBLACK_PEN );
#else
dc.SetBackgroundMode(modeOld);
dc.SetTextBackground( *wxWHITE );
dc.SetBrush( *wxWHITE_BRUSH );
#endif
dc.SetTextForeground( *wxBLACK );
}
else
dc.DrawText( child->m_text, child->m_x, child->m_y );
}; };
y += m_lineHeight; y += m_lineHeight;
if (child->NumberOfVisibleChildren() > 0) if (child->NumberOfVisibleChildren() > 0)
PaintLevel( child, dc, level+1, y ); PaintLevel( child, dc, level+1, y );
node = node->Next(); node = node->Next();
}; };
@@ -794,16 +803,16 @@ void wxTreeCtrl::OnPaint( const wxPaintEvent &WXUNUSED(event) )
if (!m_anchor) return; if (!m_anchor) return;
if (!m_dc) if (!m_dc)
{ {
m_dc = new wxPaintDC(this); m_dc = new wxPaintDC(this);
PrepareDC( *m_dc ); PrepareDC( *m_dc );
}; };
m_dc->SetFont( wxSystemSettings::GetSystemFont( wxSYS_SYSTEM_FONT ) ); m_dc->SetFont( wxSystemSettings::GetSystemFont( wxSYS_SYSTEM_FONT ) );
m_dc->SetPen( m_dottedPen ); m_dc->SetPen( m_dottedPen );
m_lineHeight = (int)(m_dc->GetCharHeight() + 4); m_lineHeight = (int)(m_dc->GetCharHeight() + 4);
int y = m_lineHeight / 2 + 2; int y = m_lineHeight / 2 + 2;
PaintLevel( m_anchor, *m_dc, 0, y ); PaintLevel( m_anchor, *m_dc, 0, y );
}; };
@@ -829,21 +838,22 @@ void wxTreeCtrl::OnMouse( const wxMouseEvent &event )
{ {
if (!event.LeftDown() && if (!event.LeftDown() &&
!event.LeftDClick()) return; !event.LeftDClick()) return;
wxClientDC dc(this); wxClientDC dc(this);
PrepareDC(dc); PrepareDC(dc);
long x = dc.DeviceToLogicalX( (long)event.GetX() ); long x = dc.DeviceToLogicalX( (long)event.GetX() );
long y = dc.DeviceToLogicalY( (long)event.GetY() ); long y = dc.DeviceToLogicalY( (long)event.GetY() );
int flag = 0; int flag = 0;
long id = HitTest( wxPoint(x,y), flag ); long id = HitTest( wxPoint(x,y), flag );
if (id == -1) return; if (id == -1)
return;
wxGenericTreeItem *item = FindItem( id ); wxGenericTreeItem *item = FindItem( id );
if (!item) return; if (!item) return;
if ((flag != wxTREE_HITTEST_ONITEMBUTTON) && if ((flag != wxTREE_HITTEST_ONITEMBUTTON) &&
(flag != wxTREE_HITTEST_ONITEMLABEL)) return; (flag != wxTREE_HITTEST_ONITEMLABEL)) return;
if (m_current != item) if (m_current != item)
{ {
if (m_current) if (m_current)
@@ -856,9 +866,10 @@ void wxTreeCtrl::OnMouse( const wxMouseEvent &event )
RefreshLine( m_current ); RefreshLine( m_current );
m_current->SendSelected( this ); m_current->SendSelected( this );
}; };
if (event.LeftDClick()) m_current->SendKeyDown( this ); if (event.LeftDClick())
m_current->SendKeyDown( this );
if (flag == wxTREE_HITTEST_ONITEMBUTTON) if (flag == wxTREE_HITTEST_ONITEMBUTTON)
{ {
ExpandItem( item->m_itemId, wxTREE_EXPAND_TOGGLE ); ExpandItem( item->m_itemId, wxTREE_EXPAND_TOGGLE );
@@ -874,37 +885,40 @@ void wxTreeCtrl::CalculateLevel( wxGenericTreeItem *item, wxPaintDC &dc, int lev
{ {
wxGenericTreeItem *child = (wxGenericTreeItem *)node->Data(); wxGenericTreeItem *child = (wxGenericTreeItem *)node->Data();
dc.SetPen( m_dottedPen ); dc.SetPen( m_dottedPen );
int startX,endX; int startX = horizX,
if ((node->Previous()) || (level != 0)) endX = horizX + 10;
startX = horizX; else startX = horizX-10;
if (child->HasChildren()) if (!node->Previous() && (level == 0))
endX = horizX+10; else endX = horizX+30; startX -= 10;
if (!child->HasChildren())
endX += 20;
child->m_x = horizX+33; child->m_x = horizX+33;
child->m_y = y-m_lineHeight/3-2; child->m_y = y-m_lineHeight/3-2;
child->m_height = m_lineHeight; child->m_height = m_lineHeight;
y += m_lineHeight; y += m_lineHeight;
if (child->NumberOfVisibleChildren() > 0) if (child->NumberOfVisibleChildren() > 0)
CalculateLevel( child, dc, level+1, y ); CalculateLevel( child, dc, level+1, y );
node = node->Next(); node = node->Next();
}; };
}; };
void wxTreeCtrl::CalculatePositions(void) void wxTreeCtrl::CalculatePositions(void)
{ {
if (!m_anchor) return; if (!m_anchor)
return;
wxClientDC dc(this); wxClientDC dc(this);
PrepareDC( dc ); PrepareDC( dc );
dc.SetFont( wxSystemSettings::GetSystemFont( wxSYS_SYSTEM_FONT ) ); dc.SetFont( wxSystemSettings::GetSystemFont( wxSYS_SYSTEM_FONT ) );
dc.SetPen( m_dottedPen ); dc.SetPen( m_dottedPen );
m_lineHeight = (int)(dc.GetCharHeight() + 4); m_lineHeight = (int)(dc.GetCharHeight() + 4);
int y = m_lineHeight / 2 + 2; int y = m_lineHeight / 2 + 2;
CalculateLevel( m_anchor, dc, 0, y ); CalculateLevel( m_anchor, dc, 0, y );
}; };