Added native selection rectangle drawing.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@43296 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
2006-11-11 00:22:20 +00:00
parent cc4a79c0f0
commit ccdbdc8936
3 changed files with 195 additions and 10 deletions

View File

@@ -220,6 +220,7 @@ public:
void OnChar( wxKeyEvent &event );
void OnMouse( wxMouseEvent &event );
void OnGetToolTip( wxTreeEvent &event );
void OnSize( wxSizeEvent &event );
void OnInternalIdle( );
virtual wxVisualAttributes GetDefaultAttributes() const

View File

@@ -52,6 +52,12 @@
#include "wx/mac/private.h"
#endif
#ifdef __WXGTK__
#include "wx/gtk/private.h"
#include "wx/gtk/win_gtk.h"
#endif
// NOTE: If using the wxListBox visual attributes works everywhere then this can
// be removed, as well as the #else case below.
@@ -71,7 +77,11 @@ static const int SCROLL_UNIT_X = 15;
static const int LINE_SPACING = 0;
// extra margins around the text label
#ifdef __WXGTK__
static const int EXTRA_WIDTH = 6;
#else
static const int EXTRA_WIDTH = 4;
#endif
static const int EXTRA_HEIGHT = 4;
// margin between the window and the items
@@ -1243,9 +1253,9 @@ void wxListLineData::SetPosition( int x, int y, int spacing )
if ( item->HasText() )
{
if (m_gi->m_rectAll.width > spacing)
m_gi->m_rectLabel.x = m_gi->m_rectAll.x + 2;
m_gi->m_rectLabel.x = m_gi->m_rectAll.x + (EXTRA_WIDTH/2);
else
m_gi->m_rectLabel.x = m_gi->m_rectAll.x + 2 + (spacing / 2) - (m_gi->m_rectLabel.width / 2);
m_gi->m_rectLabel.x = m_gi->m_rectAll.x + (EXTRA_WIDTH/2) + (spacing / 2) - (m_gi->m_rectLabel.width / 2);
m_gi->m_rectLabel.y = m_gi->m_rectAll.y + m_gi->m_rectAll.height + 2 - m_gi->m_rectLabel.height;
m_gi->m_rectHighlight.x = m_gi->m_rectLabel.x - 2;
m_gi->m_rectHighlight.y = m_gi->m_rectLabel.y - 2;
@@ -1269,11 +1279,11 @@ void wxListLineData::SetPosition( int x, int y, int spacing )
{
m_gi->m_rectIcon.x = m_gi->m_rectAll.x + 2;
m_gi->m_rectIcon.y = m_gi->m_rectAll.y + 2;
m_gi->m_rectLabel.x = m_gi->m_rectAll.x + 6 + m_gi->m_rectIcon.width;
m_gi->m_rectLabel.x = m_gi->m_rectAll.x + 4 + (EXTRA_WIDTH/2) + m_gi->m_rectIcon.width;
}
else
{
m_gi->m_rectLabel.x = m_gi->m_rectAll.x + 2;
m_gi->m_rectLabel.x = m_gi->m_rectAll.x + (EXTRA_WIDTH/2);
}
break;
@@ -1438,7 +1448,32 @@ void wxListLineData::Draw( wxDC *dc )
wxListItemAttr *attr = GetAttr();
if ( SetAttributes(dc, attr, highlighted) )
#ifndef __WXGTK__
{
dc->DrawRectangle( m_gi->m_rectHighlight );
}
#else
{
if (highlighted)
{
wxRect rect2( m_gi->m_rectHighlight );
m_owner->CalcScrolledPosition( rect2.x, rect2.y, &rect2.x, &rect2.y );
gtk_paint_flat_box( m_owner->m_widget->style,
GTK_PIZZA(m_owner->m_wxwindow)->bin_window,
GTK_STATE_SELECTED,
GTK_SHADOW_NONE,
NULL,
m_owner->m_wxwindow,
"cell_even",
rect2.x, rect2.y, rect2.width, rect2.height );
}
else
{
dc->DrawRectangle( m_gi->m_rectHighlight );
}
}
#endif
// just for debugging to better see where the items are
#if 0
@@ -1478,10 +1513,41 @@ void wxListLineData::DrawInReportMode( wxDC *dc,
// GetAttr() and move these lines into the loop below
wxListItemAttr *attr = GetAttr();
if ( SetAttributes(dc, attr, highlighted) )
#ifndef __WXGTK__
{
dc->DrawRectangle( rectHL );
}
#else
{
if (highlighted)
{
wxRect rect2( rectHL );
m_owner->CalcScrolledPosition( rect2.x, rect2.y, &rect2.x, &rect2.y );
gtk_paint_flat_box( m_owner->m_widget->style,
GTK_PIZZA(m_owner->m_wxwindow)->bin_window,
GTK_STATE_SELECTED,
GTK_SHADOW_NONE,
NULL,
m_owner->m_wxwindow,
"cell_even",
rect2.x, rect2.y, rect2.width, rect2.height );
}
else
{
dc->DrawRectangle( rectHL );
}
}
#endif
wxCoord x = rect.x + HEADER_OFFSET_X,
yMid = rect.y + rect.height/2;
#ifdef __WXGTK__
// This probably needs to be done
// on all platforms as the icons
// otherwise nearly touch the border
x += 2;
#endif
size_t col = 0;
for ( wxListItemDataList::compatibility_iterator node = m_items.GetFirst();
@@ -2729,9 +2795,23 @@ void wxListMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
{
if ( m_hasFocus )
{
wxRect rect( GetLineHighlightRect( m_current ) );
#ifndef __WXGTK__
dc.SetPen( *wxBLACK_PEN );
dc.SetBrush( *wxTRANSPARENT_BRUSH );
dc.DrawRectangle( GetLineHighlightRect( m_current ) );
dc.DrawRectangle( rect );
#else
CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
gtk_paint_focus( m_widget->style,
GTK_PIZZA(m_wxwindow)->bin_window,
GTK_STATE_SELECTED,
NULL,
m_wxwindow,
"treeview",
rect.x, rect.y, rect.width, rect.height );
#endif
}
}
#endif

View File

@@ -45,6 +45,11 @@
#include "wx/mac/private.h"
#endif
#ifdef __WXGTK__
#include "wx/gtk/private.h"
#include "wx/gtk/win_gtk.h"
#endif
// -----------------------------------------------------------------------------
// array types
// -----------------------------------------------------------------------------
@@ -720,6 +725,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxGenericTreeCtrl, wxControl)
BEGIN_EVENT_TABLE(wxGenericTreeCtrl, wxTreeCtrlBase)
EVT_PAINT (wxGenericTreeCtrl::OnPaint)
EVT_SIZE (wxGenericTreeCtrl::OnSize)
EVT_MOUSE_EVENTS (wxGenericTreeCtrl::OnMouse)
EVT_CHAR (wxGenericTreeCtrl::OnChar)
EVT_SET_FOCUS (wxGenericTreeCtrl::OnSetFocus)
@@ -2234,7 +2240,37 @@ void wxGenericTreeCtrl::PaintItem(wxGenericTreeItem *item, wxDC& dc)
int x, w, h;
x=0;
GetVirtualSize(&w, &h);
dc.DrawRectangle(x, item->GetY()+offset, w, total_h-offset);
wxRect rect( x, item->GetY()+offset, w, total_h-offset);
#ifndef __WXGTK__
dc.DrawRectangle(rect);
#else
if (!item->IsSelected())
{
dc.DrawRectangle(rect);
}
else
{
CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
gtk_paint_flat_box( m_widget->style,
GTK_PIZZA(m_wxwindow)->bin_window,
GTK_STATE_SELECTED,
GTK_SHADOW_NONE,
NULL,
m_wxwindow,
"cell_even",
rect.x, rect.y, rect.width, rect.height );
if ((item == m_current) && (m_hasFocus))
gtk_paint_focus( m_widget->style,
GTK_PIZZA(m_wxwindow)->bin_window,
GTK_STATE_SELECTED,
NULL,
m_wxwindow,
"treeview",
rect.x, rect.y, rect.width, rect.height );
}
#endif
}
else
{
@@ -2243,16 +2279,74 @@ void wxGenericTreeCtrl::PaintItem(wxGenericTreeItem *item, wxDC& dc)
// 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()+offset,
wxRect rect( item->GetX() + image_w - 2, item->GetY()+offset,
item->GetWidth() - image_w + 2, total_h-offset );
#ifndef __WXGTK__
dc.DrawRectangle( rect );
#else
CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
rect.x -= 1;
rect.width += 2;
gtk_paint_flat_box( m_widget->style,
GTK_PIZZA(m_wxwindow)->bin_window,
GTK_STATE_SELECTED,
GTK_SHADOW_NONE,
NULL,
m_wxwindow,
"cell_even",
rect.x, rect.y, rect.width, rect.height );
if ((item == m_current) && (m_hasFocus))
gtk_paint_focus( m_widget->style,
GTK_PIZZA(m_wxwindow)->bin_window,
GTK_STATE_SELECTED,
NULL,
m_wxwindow,
"treeview",
rect.x, rect.y, rect.width, rect.height );
#endif
}
// On GTK+ 2, drawing a 'normal' background is wrong for themes that
// don't allow backgrounds to be customized. Not drawing the background,
// except for custom item backgrounds, works for both kinds of theme.
else if (drawItemBackground)
{
dc.DrawRectangle( item->GetX()-2, item->GetY()+offset,
wxRect rect( item->GetX()-2, item->GetY()+offset,
item->GetWidth()+2, total_h-offset );
#ifndef __WXGTK__
dc.DrawRectangle( rect );
#else
if ( attr && attr->HasBackgroundColour() )
{
dc.DrawRectangle( rect );
}
else
{
CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
rect.x -= 1;
rect.width += 2;
gtk_paint_flat_box( m_widget->style,
GTK_PIZZA(m_wxwindow)->bin_window,
GTK_STATE_SELECTED,
GTK_SHADOW_NONE,
NULL,
m_wxwindow,
"cell_even",
rect.x, rect.y, rect.width, rect.height );
if ((item == m_current) && (m_hasFocus))
gtk_paint_focus( m_widget->style,
GTK_PIZZA(m_wxwindow)->bin_window,
GTK_STATE_SELECTED,
NULL,
m_wxwindow,
"treeview",
rect.x, rect.y, rect.width, rect.height );
}
#endif
}
}
@@ -2540,6 +2634,16 @@ void wxGenericTreeCtrl::DrawLine(const wxTreeItemId &item, bool below)
// wxWidgets callbacks
// -----------------------------------------------------------------------------
void wxGenericTreeCtrl::OnSize( wxSizeEvent &event )
{
#ifdef __WXGTK__
if (HasFlag( wxTR_FULL_ROW_HIGHLIGHT) && m_current)
RefreshLine( m_current );
#endif
event.Skip(true);
}
void wxGenericTreeCtrl::OnPaint( wxPaintEvent &WXUNUSED(event) )
{
wxPaintDC dc(this);