#include "wx/wxprec.h"
#ifdef __BORLANDC__
-#pragma hdrstop
+ #pragma hdrstop
#endif
+#if wxUSE_TREECTRL
+
#include "wx/generic/treectlg.h"
#include "wx/imaglist.h"
#include "wx/settings.h"
SetValidator( validator );
#endif
-#ifndef __WXMAC__
SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_LISTBOX ) );
-#endif
// m_dottedPen = wxPen( "grey", 0, wxDOT ); too slow under XFree86
m_dottedPen = wxPen( "grey", 0, 0 );
if ( GetEventHandler()->ProcessEvent( event ) && !event.IsAllowed() )
return;
+ wxTreeItemId parent = GetParent( itemId );
+ while (parent.IsOk())
+ {
+ if (!IsExpanded(parent))
+ Expand( parent );
+
+ parent = GetParent( parent );
+ }
+
+ EnsureVisible( itemId );
+
// ctrl press
if (unselect_others)
{
int start_x = 0;
int start_y = 0;
- ViewStart( &start_x, &start_y );
+ GetViewStart( &start_x, &start_y );
start_y *= PIXELS_PER_UNIT;
int client_h = 0;
int total_h = GetLineHeight(item);
- if (item->IsSelected())
+ bool paintBg = item->IsSelected() && m_hasFocus;
+ if ( paintBg )
+ {
dc.SetBrush(*m_hilightBrush);
+ }
else
{
wxColour colBg;
dc.SetBrush(wxBrush(colBg, wxSOLID));
}
- if (item->IsSelected() && image != NO_IMAGE)
+ int offset = HasFlag(wxTR_ROW_LINES) ? 1 : 0;
+
+ if ( item->IsSelected() && image != NO_IMAGE)
{
// If it's selected, and there's an image, then we should
// take care to leave the area under the image painted in the
// background colour.
- dc.DrawRectangle( item->GetX() + image_w - 2, item->GetY(), item->GetWidth() - image_w + 2, total_h );
+ dc.DrawRectangle( item->GetX() + image_w - 2, item->GetY()+offset,
+ item->GetWidth() - image_w + 2, total_h-offset );
}
else
- dc.DrawRectangle( item->GetX()-2, item->GetY(), item->GetWidth()+2, total_h );
+ {
+ dc.DrawRectangle( item->GetX()-2, item->GetY()+offset,
+ item->GetWidth()+2, total_h-offset );
+ }
if ( image != NO_IMAGE )
{
// Now y stands for the top of the item, whereas it used to stand for middle !
void wxGenericTreeCtrl::PaintLevel( wxGenericTreeItem *item, wxDC &dc, int level, int &y )
{
- int horizX = level*m_indent;
+ int x = (level+1)*m_indent;
- item->SetX( horizX+m_indent+m_spacing );
+ item->SetX( x+m_spacing );
item->SetY( y );
int oldY = y;
y+=GetLineHeight(item)/2;
- item->SetCross( horizX+m_indent, y );
+ item->SetCross( x, y );
int exposed_x = dc.LogicalToDeviceX( 0 );
int exposed_y = dc.LogicalToDeviceY( item->GetY() );
- bool drawLines = ((GetWindowStyle() & wxTR_NO_LINES) == 0);
+ bool drawLines = (!HasFlag(wxTR_NO_LINES) && !HasFlag(wxTR_MAC_BUTTONS));
if (IsExposed( exposed_x, exposed_y, 10000, GetLineHeight(item) )) // 10000 = very much
{
- int startX = horizX;
- int endX = horizX + (m_indent-5);
+ int startX = x - m_indent;
+ int endX = x-5;
-// if (!item->HasChildren()) endX += (m_indent+5);
if (!item->HasChildren()) endX += 20;
-
+
if (HasFlag( wxTR_MAC_BUTTONS ))
{
if (item->HasPlus())
{
dc.SetPen( *wxBLACK_PEN );
dc.SetBrush( *m_hilightBrush );
-
+
wxPoint button[3];
- int x = horizX + m_indent;
-
+
if (item->IsExpanded())
{
button[0].x = x-5;
button[2].x = x+3;
}
dc.DrawPolygon( 3, button );
-
+
dc.SetPen( m_dottedPen );
}
}
if (item->HasPlus())
{
if (drawLines)
- dc.DrawLine( horizX+(m_indent+5), y, horizX+(m_indent+15), y );
+ dc.DrawLine( x+5, y, x+15, y );
dc.SetPen( *wxGREY_PEN );
dc.SetBrush( *wxWHITE_BRUSH );
- dc.DrawRectangle( horizX+(m_indent-5), y-4, 11, 9 );
+ dc.DrawRectangle( x-5, y-4, 11, 9 );
dc.SetPen( *wxBLACK_PEN );
- dc.DrawLine( horizX+(m_indent-2), y, horizX+(m_indent+3), y );
+ dc.DrawLine( x-2, y, x+3, y );
if (!item->IsExpanded())
- dc.DrawLine( horizX+m_indent, y-2, horizX+m_indent, y+3 );
+ dc.DrawLine( x, y-2, x, y+3 );
dc.SetPen( m_dottedPen );
}
}
- wxPen *pen = wxTRANSPARENT_PEN;
- wxColour colText;
-
+ wxPen *pen;
+#ifndef __WXMAC__
+ // don't draw rect outline if we already have the background color
+ // under Max
if ( item->IsSelected() )
+ pen = wxBLACK_PEN;
+ else
+#endif // !__WXMAC__
+ pen = wxTRANSPARENT_PEN;
+
+ wxColour colText;
+ if ( item->IsSelected() && m_hasFocus )
{
colText = wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT );
-
- if ( m_hasFocus )
- pen = wxBLACK_PEN;
-
}
else
{
// draw
PaintItem(item, dc);
+ if (HasFlag( wxTR_ROW_LINES ))
+ {
+ dc.SetPen( *wxWHITE_PEN );
+ dc.DrawLine( 0, oldY, 10000, oldY );
+ dc.DrawLine( 0, oldY + GetLineHeight(item), 10000, oldY + GetLineHeight(item) );
+ }
+
// restore DC objects
dc.SetBrush( *wxWHITE_BRUSH );
dc.SetPen( m_dottedPen );
{
semiOldY+=GetLineHeight(children[--n])/2;
if (drawLines)
- dc.DrawLine( horizX+m_indent, oldY+5, horizX+m_indent, semiOldY );
+ dc.DrawLine( x, oldY+5, x, semiOldY );
}
}
}
{
m_hasFocus = TRUE;
- if (m_current) RefreshLine( m_current );
+ if (m_current)
+ RefreshLine( m_current );
}
void wxGenericTreeCtrl::OnKillFocus( wxFocusEvent &WXUNUSED(event) )
{
m_hasFocus = FALSE;
- if (m_current) RefreshLine( m_current );
+ if (m_current)
+ RefreshLine( m_current );
}
void wxGenericTreeCtrl::OnChar( wxKeyEvent &event )
// erase the highlighting
DrawDropEffect(m_dropTarget);
+ if ( m_oldSelection )
+ {
+ m_oldSelection->SetHilight(TRUE);
+ RefreshLine(m_oldSelection);
+ m_oldSelection = (wxGenericTreeItem *)NULL;
+ }
+
// generate the drag end event
wxTreeEvent event(wxEVT_COMMAND_TREE_END_DRAG, GetId());
m_isDragging = FALSE;
m_dropTarget = (wxGenericTreeItem *)NULL;
- if ( m_oldSelection )
- {
- m_oldSelection->SetHilight(TRUE);
- RefreshLine(m_oldSelection);
- m_oldSelection = (wxGenericTreeItem *)NULL;
- }
-
ReleaseMouse();
SetCursor(m_oldCursor);
Refresh( TRUE, &rect );
}
+#endif // wxUSE_TREECTRL