Redid parts of wxScroledWindow
Corrected scrollling (speed) in wxListCtrl git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1175 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -522,7 +522,11 @@ void wxListLineData::DoDraw( wxPaintDC *dc, bool hilight, bool paintBG )
|
||||
long dev_y = dc->LogicalToDeviceY( m_bound_all.y-2 );
|
||||
long dev_w = dc->LogicalToDeviceXRel( m_bound_all.width+4 );
|
||||
long dev_h = dc->LogicalToDeviceYRel( m_bound_all.height+4 );
|
||||
if (!m_owner->IsExposed( dev_x, dev_y, dev_w, dev_h ) ) return;
|
||||
|
||||
if (!m_owner->IsExposed( dev_x, dev_y, dev_w, dev_h ))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (paintBG)
|
||||
{
|
||||
@@ -969,7 +973,6 @@ wxListMainWindow::wxListMainWindow( wxWindow *parent, wxWindowID id,
|
||||
m_normal_image_list = (wxImageList *) NULL;
|
||||
m_small_spacing = 30;
|
||||
m_normal_spacing = 40;
|
||||
// AllowDoubleClick( TRUE );
|
||||
m_hasFocus = FALSE;
|
||||
m_dragCount = 0;
|
||||
m_isCreated = FALSE;
|
||||
@@ -992,8 +995,6 @@ wxListMainWindow::wxListMainWindow( wxWindow *parent, wxWindowID id,
|
||||
m_lastOnSame = FALSE;
|
||||
m_renameTimer = new wxListRenameTimer( this );
|
||||
m_renameAccept = FALSE;
|
||||
// m_text = new wxRawListTextCtrl( GetParent(), "", &m_renameAccept, &m_renameRes, this, 10, 10, 40, 10 );
|
||||
// m_text->Show( FALSE );
|
||||
|
||||
SetBackgroundColour( *wxWHITE );
|
||||
}
|
||||
@@ -1001,9 +1002,8 @@ wxListMainWindow::wxListMainWindow( wxWindow *parent, wxWindowID id,
|
||||
wxListMainWindow::~wxListMainWindow( void )
|
||||
{
|
||||
if (m_hilightBrush) delete m_hilightBrush;
|
||||
|
||||
delete m_renameTimer;
|
||||
// if (m_hilightColour) delete m_hilightColour;
|
||||
// delete m_text;
|
||||
}
|
||||
|
||||
void wxListMainWindow::RefreshLine( wxListLineData *line )
|
||||
@@ -1030,6 +1030,8 @@ void wxListMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
|
||||
{
|
||||
if (m_dirty) return;
|
||||
|
||||
if (m_lines.GetCount() == 0) return;
|
||||
|
||||
wxPaintDC dc( this );
|
||||
PrepareDC( dc );
|
||||
|
||||
@@ -1037,6 +1039,28 @@ void wxListMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
|
||||
|
||||
dc.SetFont( GetFont() );
|
||||
|
||||
if (m_mode & wxLC_REPORT)
|
||||
{
|
||||
int lineSpacing = 0;
|
||||
wxListLineData *line = (wxListLineData*)m_lines.First()->Data();
|
||||
int dummy = 0;
|
||||
line->GetSize( dummy, lineSpacing );
|
||||
lineSpacing += 1;
|
||||
|
||||
int y_s = m_yScroll*GetScrollPos( wxVERTICAL );
|
||||
|
||||
wxNode *node = m_lines.Nth( y_s / lineSpacing );
|
||||
for (int i = 0; i < m_visibleLines+2; i++)
|
||||
{
|
||||
if (!node) break;
|
||||
|
||||
line = (wxListLineData*)node->Data();
|
||||
line->Draw( &dc );
|
||||
node = node->Next();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
wxNode *node = m_lines.First();
|
||||
while (node)
|
||||
{
|
||||
@@ -1044,6 +1068,8 @@ void wxListMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
|
||||
line->Draw( &dc );
|
||||
node = node->Next();
|
||||
}
|
||||
}
|
||||
|
||||
if (m_current) m_current->DrawRubberBand( &dc, m_hasFocus );
|
||||
|
||||
dc.EndDrawing();
|
||||
@@ -1307,26 +1333,24 @@ void wxListMainWindow::MoveToFocus( void )
|
||||
int w = 0;
|
||||
int h = 0;
|
||||
m_current->GetExtent( x, y, w, h );
|
||||
|
||||
int w_p = 0;
|
||||
int h_p = 0;
|
||||
GetClientSize( &w_p, &h_p );
|
||||
|
||||
if (m_mode & wxLC_REPORT)
|
||||
{
|
||||
if (GetScrollPos( wxHORIZONTAL ) != 0) SetScrollPos( wxHORIZONTAL, 0);
|
||||
int y_s = m_yScroll*GetScrollPos( wxVERTICAL );
|
||||
if ((y > y_s) && (y+h < y_s+h_p)) return;
|
||||
if (y-y_s < 5) SetScrollPos( wxVERTICAL, (y-5-h_p/2)/m_yScroll );
|
||||
if (y+h+5 > y_s+h_p) SetScrollPos( wxVERTICAL, (y+h-h_p/2+h+15)/m_yScroll );
|
||||
m_dirty = TRUE;
|
||||
if (y-y_s < 5) Scroll( -1, (y-5-h_p/2)/m_yScroll );
|
||||
if (y+h+5 > y_s+h_p) Scroll( -1, (y+h-h_p/2+h+15)/m_yScroll );
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GetScrollPos( wxVERTICAL ) != 0) SetScrollPos( wxVERTICAL, 0);
|
||||
int x_s = m_xScroll*GetScrollPos( wxHORIZONTAL );
|
||||
if ((x > x_s) && (x+w < x_s+w_p)) return;
|
||||
if (x-x_s < 5) SetScrollPos( wxHORIZONTAL, (x-5)/m_xScroll );
|
||||
if (x+w-5 > x_s+w_p) SetScrollPos( wxHORIZONTAL, (x+w-w_p+15)/m_xScroll );
|
||||
m_dirty = TRUE;
|
||||
if (x-x_s < 5) Scroll( (x-5)/m_xScroll, -1 );
|
||||
if (x+w-5 > x_s+w_p) Scroll( (x+w-w_p+15)/m_xScroll, -1 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1727,11 +1751,14 @@ void wxListMainWindow::SetItemState( long item, long state, long stateMask )
|
||||
RefreshLine( oldCurrent );
|
||||
}
|
||||
bool on = state & wxLIST_STATE_SELECTED;
|
||||
if (on != line->IsHilighted())
|
||||
{
|
||||
line->Hilight( on );
|
||||
RefreshLine( line );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int wxListMainWindow::GetItemState( long item, long stateMask )
|
||||
{
|
||||
@@ -1904,7 +1931,7 @@ void wxListMainWindow::CalculatePositions( void )
|
||||
y += lineSpacing; // one pixel blank line between items
|
||||
node = node->Next();
|
||||
}
|
||||
m_visibleLines = m_lines.GetCount();
|
||||
m_visibleLines = clientHeight / lineSpacing;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -119,8 +119,7 @@ void wxScrolledWindow::OnScroll(wxScrollEvent& event)
|
||||
int orient = event.GetOrientation();
|
||||
|
||||
int nScrollInc = CalcScrollInc(event);
|
||||
if (nScrollInc == 0)
|
||||
return;
|
||||
if (nScrollInc == 0) return;
|
||||
|
||||
// TODO: should we store the scroll position here as well as in wxWindow?
|
||||
if (orient == wxHORIZONTAL)
|
||||
@@ -170,7 +169,6 @@ void wxScrolledWindow::OnScroll(wxScrollEvent& event)
|
||||
else
|
||||
Refresh();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int wxScrolledWindow::CalcScrollInc(wxScrollEvent& event)
|
||||
@@ -284,26 +282,21 @@ void wxScrolledWindow::AdjustScrollbars(void)
|
||||
int w, h;
|
||||
GetClientSize(&w, &h);
|
||||
|
||||
// Recalculate scroll bar range and position
|
||||
if (m_xScrollLines > 0)
|
||||
{
|
||||
int nMaxWidth = m_xScrollLines*m_xScrollPixelsPerLine;
|
||||
int newRange = (int) ( ((nMaxWidth)/(float)m_xScrollPixelsPerLine) + 0.5 );
|
||||
if (newRange < 0)
|
||||
newRange = 0;
|
||||
|
||||
m_xScrollPosition = wxMin(newRange, m_xScrollPosition);
|
||||
|
||||
// Calculate page size i.e. number of scroll units you get on the
|
||||
// current client window
|
||||
int noPagePositions = (int) ( (w/(float)m_xScrollPixelsPerLine) + 0.5 );
|
||||
if (noPagePositions < 1)
|
||||
noPagePositions = 1;
|
||||
if (noPagePositions < 1) noPagePositions = 1;
|
||||
|
||||
SetScrollbar(wxHORIZONTAL, m_xScrollPosition, noPagePositions, newRange);
|
||||
SetScrollPageSize(wxHORIZONTAL, noPagePositions);
|
||||
// Correct position if greater than extent of canvas minus
|
||||
// the visible portion of it or if below zero
|
||||
m_xScrollPosition = wxMin( m_xScrollLines-noPagePositions, m_xScrollPosition);
|
||||
m_xScrollPosition = wxMax( 0, m_xScrollPosition );
|
||||
|
||||
SetScrollbar(wxHORIZONTAL, m_xScrollPosition, noPagePositions, m_xScrollLines);
|
||||
// SetScrollPageSize(wxHORIZONTAL, noPagePositions);
|
||||
}
|
||||
// Robert Roebling
|
||||
else
|
||||
{
|
||||
m_xScrollPosition = 0;
|
||||
@@ -312,36 +305,31 @@ void wxScrolledWindow::AdjustScrollbars(void)
|
||||
|
||||
if (m_yScrollLines > 0)
|
||||
{
|
||||
int nMaxHeight = m_yScrollLines*m_yScrollPixelsPerLine;
|
||||
int newRange = (int) ( ((nMaxHeight)/(float)m_yScrollPixelsPerLine) + 0.5 );
|
||||
if (newRange < 0)
|
||||
newRange = 0;
|
||||
|
||||
m_yScrollPosition = wxMin(newRange, m_yScrollPosition);
|
||||
|
||||
// Calculate page size i.e. number of scroll units you get on the
|
||||
// current client window
|
||||
int noPagePositions = (int) ( (h/(float)m_yScrollPixelsPerLine) + 0.5 );
|
||||
if (noPagePositions < 1)
|
||||
noPagePositions = 1;
|
||||
if (noPagePositions < 1) noPagePositions = 1;
|
||||
|
||||
SetScrollbar(wxVERTICAL, m_yScrollPosition, noPagePositions, newRange);
|
||||
SetScrollPageSize(wxVERTICAL, noPagePositions);
|
||||
// Correct position if greater than extent of canvas minus
|
||||
// the visible portion of it or if below zero
|
||||
m_yScrollPosition = wxMin( m_yScrollLines-noPagePositions, m_yScrollPosition );
|
||||
m_yScrollPosition = wxMax( 0, m_yScrollPosition );
|
||||
|
||||
SetScrollbar(wxVERTICAL, m_yScrollPosition, noPagePositions, m_yScrollLines);
|
||||
// SetScrollPageSize(wxVERTICAL, noPagePositions);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_yScrollPosition = 0;
|
||||
SetScrollbar (wxVERTICAL, 0, 0, 0, FALSE); // Robert Roebling
|
||||
SetScrollbar (wxVERTICAL, 0, 0, 0, FALSE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Default OnSize resets scrollbars, if any
|
||||
void wxScrolledWindow::OnSize(wxSizeEvent& WXUNUSED(event))
|
||||
{
|
||||
#if wxUSE_CONSTRAINTS
|
||||
if (GetAutoLayout())
|
||||
Layout();
|
||||
if (GetAutoLayout()) Layout();
|
||||
#endif
|
||||
|
||||
AdjustScrollbars();
|
||||
@@ -361,7 +349,8 @@ void wxScrolledWindow::OnPaint(wxPaintEvent& WXUNUSED(event))
|
||||
// automatically change the origin according to the scroll position.
|
||||
void wxScrolledWindow::PrepareDC(wxDC& dc)
|
||||
{
|
||||
dc.SetDeviceOrigin(- m_xScrollPosition * m_xScrollPixelsPerLine, - m_yScrollPosition * m_yScrollPixelsPerLine);
|
||||
dc.SetDeviceOrigin( -m_xScrollPosition * m_xScrollPixelsPerLine,
|
||||
-m_yScrollPosition * m_yScrollPixelsPerLine );
|
||||
dc.SetUserScale( m_scaleX, m_scaleY );
|
||||
}
|
||||
|
||||
@@ -400,22 +389,47 @@ void wxScrolledWindow::SetScrollPageSize(int orient, int pageSize)
|
||||
*/
|
||||
void wxScrolledWindow::Scroll( int x_pos, int y_pos )
|
||||
{
|
||||
int old_x, old_y;
|
||||
ViewStart (&old_x, &old_y);
|
||||
if (((x_pos == -1) || (x_pos == old_x)) && ((y_pos == -1) || (y_pos == old_y)))
|
||||
return;
|
||||
if (((x_pos == -1) || (x_pos == m_xScrollPosition)) &&
|
||||
((y_pos == -1) || (y_pos == m_yScrollPosition))) return;
|
||||
|
||||
if (x_pos > -1)
|
||||
int w, h;
|
||||
GetClientSize(&w, &h);
|
||||
|
||||
if (x_pos != -1)
|
||||
{
|
||||
m_xScrollPosition = x_pos;
|
||||
SetScrollPos (wxHORIZONTAL, x_pos, TRUE);
|
||||
|
||||
// Calculate page size i.e. number of scroll units you get on the
|
||||
// current client window
|
||||
int noPagePositions = (int) ( (w/(float)m_xScrollPixelsPerLine) + 0.5 );
|
||||
if (noPagePositions < 1) noPagePositions = 1;
|
||||
|
||||
// Correct position if greater than extent of canvas minus
|
||||
// the visible portion of it or if below zero
|
||||
m_xScrollPosition = wxMin( m_xScrollLines-noPagePositions, m_xScrollPosition );
|
||||
m_xScrollPosition = wxMax( 0, m_xScrollPosition );
|
||||
|
||||
SetScrollPos( wxHORIZONTAL, m_xScrollPosition, TRUE );
|
||||
}
|
||||
if (y_pos > -1)
|
||||
if (y_pos != -1)
|
||||
{
|
||||
m_yScrollPosition = y_pos;
|
||||
SetScrollPos (wxVERTICAL, y_pos, TRUE);
|
||||
|
||||
// Calculate page size i.e. number of scroll units you get on the
|
||||
// current client window
|
||||
int noPagePositions = (int) ( (h/(float)m_yScrollPixelsPerLine) + 0.5 );
|
||||
if (noPagePositions < 1) noPagePositions = 1;
|
||||
|
||||
// Correct position if greater than extent of canvas minus
|
||||
// the visible portion of it or if below zero
|
||||
m_yScrollPosition = wxMin( m_yScrollLines-noPagePositions, m_yScrollPosition );
|
||||
m_yScrollPosition = wxMax( 0, m_yScrollPosition );
|
||||
|
||||
SetScrollPos( wxVERTICAL, m_yScrollPosition, TRUE );
|
||||
}
|
||||
|
||||
Refresh();
|
||||
|
||||
#ifdef __WXMSW__
|
||||
::UpdateWindow ((HWND) GetHWND());
|
||||
#endif
|
||||
|
@@ -2001,34 +2001,29 @@ void wxWindow::SetCursor( const wxCursor &cursor )
|
||||
|
||||
void wxWindow::Refresh( bool eraseBackground, const wxRect *rect )
|
||||
{
|
||||
wxASSERT_MSG( (m_widget != NULL), "invalid window" );
|
||||
wxCHECK_RET( (m_widget != NULL), "invalid window" );
|
||||
|
||||
if (eraseBackground && m_wxwindow && m_wxwindow->window)
|
||||
{
|
||||
if (rect)
|
||||
{
|
||||
gdk_window_clear_area( m_wxwindow->window,
|
||||
rect->x,
|
||||
rect->y,
|
||||
rect->x, rect->y,
|
||||
rect->width,
|
||||
rect->height );
|
||||
}
|
||||
else
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
}
|
||||
|
||||
if (!rect)
|
||||
{
|
||||
if (m_wxwindow)
|
||||
{
|
||||
int w = 0;
|
||||
int h = 0;
|
||||
GetClientSize( &w, &h );
|
||||
|
||||
GdkRectangle gdk_rect;
|
||||
gdk_rect.x = 0;
|
||||
gdk_rect.y = 0;
|
||||
gdk_rect.width = w;
|
||||
gdk_rect.height = h;
|
||||
gtk_widget_draw( m_wxwindow, &gdk_rect );
|
||||
}
|
||||
gtk_widget_draw( m_wxwindow, (GdkRectangle*) NULL );
|
||||
else
|
||||
gtk_widget_draw( m_widget, (GdkRectangle*) NULL );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -2001,34 +2001,29 @@ void wxWindow::SetCursor( const wxCursor &cursor )
|
||||
|
||||
void wxWindow::Refresh( bool eraseBackground, const wxRect *rect )
|
||||
{
|
||||
wxASSERT_MSG( (m_widget != NULL), "invalid window" );
|
||||
wxCHECK_RET( (m_widget != NULL), "invalid window" );
|
||||
|
||||
if (eraseBackground && m_wxwindow && m_wxwindow->window)
|
||||
{
|
||||
if (rect)
|
||||
{
|
||||
gdk_window_clear_area( m_wxwindow->window,
|
||||
rect->x,
|
||||
rect->y,
|
||||
rect->x, rect->y,
|
||||
rect->width,
|
||||
rect->height );
|
||||
}
|
||||
else
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
}
|
||||
|
||||
if (!rect)
|
||||
{
|
||||
if (m_wxwindow)
|
||||
{
|
||||
int w = 0;
|
||||
int h = 0;
|
||||
GetClientSize( &w, &h );
|
||||
|
||||
GdkRectangle gdk_rect;
|
||||
gdk_rect.x = 0;
|
||||
gdk_rect.y = 0;
|
||||
gdk_rect.width = w;
|
||||
gdk_rect.height = h;
|
||||
gtk_widget_draw( m_wxwindow, &gdk_rect );
|
||||
}
|
||||
gtk_widget_draw( m_wxwindow, (GdkRectangle*) NULL );
|
||||
else
|
||||
gtk_widget_draw( m_widget, (GdkRectangle*) NULL );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Reference in New Issue
Block a user