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:
Robert Roebling
1998-12-11 19:28:38 +00:00
parent 50c319beec
commit 139adb6a28
4 changed files with 471 additions and 440 deletions

View File

@@ -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_y = dc->LogicalToDeviceY( m_bound_all.y-2 );
long dev_w = dc->LogicalToDeviceXRel( m_bound_all.width+4 ); long dev_w = dc->LogicalToDeviceXRel( m_bound_all.width+4 );
long dev_h = dc->LogicalToDeviceYRel( m_bound_all.height+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) if (paintBG)
{ {
@@ -969,7 +973,6 @@ wxListMainWindow::wxListMainWindow( wxWindow *parent, wxWindowID id,
m_normal_image_list = (wxImageList *) NULL; m_normal_image_list = (wxImageList *) NULL;
m_small_spacing = 30; m_small_spacing = 30;
m_normal_spacing = 40; m_normal_spacing = 40;
// AllowDoubleClick( TRUE );
m_hasFocus = FALSE; m_hasFocus = FALSE;
m_dragCount = 0; m_dragCount = 0;
m_isCreated = FALSE; m_isCreated = FALSE;
@@ -992,8 +995,6 @@ wxListMainWindow::wxListMainWindow( wxWindow *parent, wxWindowID id,
m_lastOnSame = FALSE; m_lastOnSame = FALSE;
m_renameTimer = new wxListRenameTimer( this ); m_renameTimer = new wxListRenameTimer( this );
m_renameAccept = FALSE; m_renameAccept = FALSE;
// m_text = new wxRawListTextCtrl( GetParent(), "", &m_renameAccept, &m_renameRes, this, 10, 10, 40, 10 );
// m_text->Show( FALSE );
SetBackgroundColour( *wxWHITE ); SetBackgroundColour( *wxWHITE );
} }
@@ -1001,9 +1002,8 @@ wxListMainWindow::wxListMainWindow( wxWindow *parent, wxWindowID id,
wxListMainWindow::~wxListMainWindow( void ) wxListMainWindow::~wxListMainWindow( void )
{ {
if (m_hilightBrush) delete m_hilightBrush; if (m_hilightBrush) delete m_hilightBrush;
delete m_renameTimer; delete m_renameTimer;
// if (m_hilightColour) delete m_hilightColour;
// delete m_text;
} }
void wxListMainWindow::RefreshLine( wxListLineData *line ) void wxListMainWindow::RefreshLine( wxListLineData *line )
@@ -1030,6 +1030,8 @@ void wxListMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
{ {
if (m_dirty) return; if (m_dirty) return;
if (m_lines.GetCount() == 0) return;
wxPaintDC dc( this ); wxPaintDC dc( this );
PrepareDC( dc ); PrepareDC( dc );
@@ -1037,6 +1039,28 @@ void wxListMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
dc.SetFont( GetFont() ); 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(); wxNode *node = m_lines.First();
while (node) while (node)
{ {
@@ -1044,6 +1068,8 @@ void wxListMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
line->Draw( &dc ); line->Draw( &dc );
node = node->Next(); node = node->Next();
} }
}
if (m_current) m_current->DrawRubberBand( &dc, m_hasFocus ); if (m_current) m_current->DrawRubberBand( &dc, m_hasFocus );
dc.EndDrawing(); dc.EndDrawing();
@@ -1307,26 +1333,24 @@ void wxListMainWindow::MoveToFocus( void )
int w = 0; int w = 0;
int h = 0; int h = 0;
m_current->GetExtent( x, y, w, h ); m_current->GetExtent( x, y, w, h );
int w_p = 0; int w_p = 0;
int h_p = 0; int h_p = 0;
GetClientSize( &w_p, &h_p ); GetClientSize( &w_p, &h_p );
if (m_mode & wxLC_REPORT) if (m_mode & wxLC_REPORT)
{ {
if (GetScrollPos( wxHORIZONTAL ) != 0) SetScrollPos( wxHORIZONTAL, 0);
int y_s = m_yScroll*GetScrollPos( wxVERTICAL ); int y_s = m_yScroll*GetScrollPos( wxVERTICAL );
if ((y > y_s) && (y+h < y_s+h_p)) return; 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-y_s < 5) Scroll( -1, (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 ); if (y+h+5 > y_s+h_p) Scroll( -1, (y+h-h_p/2+h+15)/m_yScroll );
m_dirty = TRUE;
} }
else else
{ {
if (GetScrollPos( wxVERTICAL ) != 0) SetScrollPos( wxVERTICAL, 0);
int x_s = m_xScroll*GetScrollPos( wxHORIZONTAL ); int x_s = m_xScroll*GetScrollPos( wxHORIZONTAL );
if ((x > x_s) && (x+w < x_s+w_p)) return; if ((x > x_s) && (x+w < x_s+w_p)) return;
if (x-x_s < 5) SetScrollPos( wxHORIZONTAL, (x-5)/m_xScroll ); if (x-x_s < 5) Scroll( (x-5)/m_xScroll, -1 );
if (x+w-5 > x_s+w_p) SetScrollPos( wxHORIZONTAL, (x+w-w_p+15)/m_xScroll ); if (x+w-5 > x_s+w_p) Scroll( (x+w-w_p+15)/m_xScroll, -1 );
m_dirty = TRUE;
} }
} }
@@ -1727,10 +1751,13 @@ void wxListMainWindow::SetItemState( long item, long state, long stateMask )
RefreshLine( oldCurrent ); RefreshLine( oldCurrent );
} }
bool on = state & wxLIST_STATE_SELECTED; bool on = state & wxLIST_STATE_SELECTED;
if (on != line->IsHilighted())
{
line->Hilight( on ); line->Hilight( on );
RefreshLine( line ); RefreshLine( line );
} }
} }
}
} }
int wxListMainWindow::GetItemState( long item, long stateMask ) int wxListMainWindow::GetItemState( long item, long stateMask )
@@ -1904,7 +1931,7 @@ void wxListMainWindow::CalculatePositions( void )
y += lineSpacing; // one pixel blank line between items y += lineSpacing; // one pixel blank line between items
node = node->Next(); node = node->Next();
} }
m_visibleLines = m_lines.GetCount(); m_visibleLines = clientHeight / lineSpacing;
} }
else else
{ {

View File

@@ -119,8 +119,7 @@ void wxScrolledWindow::OnScroll(wxScrollEvent& event)
int orient = event.GetOrientation(); int orient = event.GetOrientation();
int nScrollInc = CalcScrollInc(event); int nScrollInc = CalcScrollInc(event);
if (nScrollInc == 0) if (nScrollInc == 0) return;
return;
// TODO: should we store the scroll position here as well as in wxWindow? // TODO: should we store the scroll position here as well as in wxWindow?
if (orient == wxHORIZONTAL) if (orient == wxHORIZONTAL)
@@ -170,7 +169,6 @@ void wxScrolledWindow::OnScroll(wxScrollEvent& event)
else else
Refresh(); Refresh();
} }
} }
int wxScrolledWindow::CalcScrollInc(wxScrollEvent& event) int wxScrolledWindow::CalcScrollInc(wxScrollEvent& event)
@@ -284,26 +282,21 @@ void wxScrolledWindow::AdjustScrollbars(void)
int w, h; int w, h;
GetClientSize(&w, &h); GetClientSize(&w, &h);
// Recalculate scroll bar range and position
if (m_xScrollLines > 0) 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 // Calculate page size i.e. number of scroll units you get on the
// current client window // current client window
int noPagePositions = (int) ( (w/(float)m_xScrollPixelsPerLine) + 0.5 ); int noPagePositions = (int) ( (w/(float)m_xScrollPixelsPerLine) + 0.5 );
if (noPagePositions < 1) if (noPagePositions < 1) noPagePositions = 1;
noPagePositions = 1;
SetScrollbar(wxHORIZONTAL, m_xScrollPosition, noPagePositions, newRange); // Correct position if greater than extent of canvas minus
SetScrollPageSize(wxHORIZONTAL, noPagePositions); // 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 else
{ {
m_xScrollPosition = 0; m_xScrollPosition = 0;
@@ -312,36 +305,31 @@ void wxScrolledWindow::AdjustScrollbars(void)
if (m_yScrollLines > 0) 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 // Calculate page size i.e. number of scroll units you get on the
// current client window // current client window
int noPagePositions = (int) ( (h/(float)m_yScrollPixelsPerLine) + 0.5 ); int noPagePositions = (int) ( (h/(float)m_yScrollPixelsPerLine) + 0.5 );
if (noPagePositions < 1) if (noPagePositions < 1) noPagePositions = 1;
noPagePositions = 1;
SetScrollbar(wxVERTICAL, m_yScrollPosition, noPagePositions, newRange); // Correct position if greater than extent of canvas minus
SetScrollPageSize(wxVERTICAL, noPagePositions); // 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 else
{ {
m_yScrollPosition = 0; m_yScrollPosition = 0;
SetScrollbar (wxVERTICAL, 0, 0, 0, FALSE); // Robert Roebling SetScrollbar (wxVERTICAL, 0, 0, 0, FALSE);
} }
} }
// Default OnSize resets scrollbars, if any // Default OnSize resets scrollbars, if any
void wxScrolledWindow::OnSize(wxSizeEvent& WXUNUSED(event)) void wxScrolledWindow::OnSize(wxSizeEvent& WXUNUSED(event))
{ {
#if wxUSE_CONSTRAINTS #if wxUSE_CONSTRAINTS
if (GetAutoLayout()) if (GetAutoLayout()) Layout();
Layout();
#endif #endif
AdjustScrollbars(); AdjustScrollbars();
@@ -361,8 +349,9 @@ void wxScrolledWindow::OnPaint(wxPaintEvent& WXUNUSED(event))
// automatically change the origin according to the scroll position. // automatically change the origin according to the scroll position.
void wxScrolledWindow::PrepareDC(wxDC& dc) void wxScrolledWindow::PrepareDC(wxDC& dc)
{ {
dc.SetDeviceOrigin(- m_xScrollPosition * m_xScrollPixelsPerLine, - m_yScrollPosition * m_yScrollPixelsPerLine); dc.SetDeviceOrigin( -m_xScrollPosition * m_xScrollPixelsPerLine,
dc.SetUserScale(m_scaleX, m_scaleY); -m_yScrollPosition * m_yScrollPixelsPerLine );
dc.SetUserScale( m_scaleX, m_scaleY );
} }
#if WXWIN_COMPATIBILITY #if WXWIN_COMPATIBILITY
@@ -398,24 +387,49 @@ void wxScrolledWindow::SetScrollPageSize(int orient, int pageSize)
/* /*
* Scroll to given position (scroll position, not pixel position) * Scroll to given position (scroll position, not pixel position)
*/ */
void wxScrolledWindow::Scroll (int x_pos, int y_pos) void wxScrolledWindow::Scroll( int x_pos, int y_pos )
{ {
int old_x, old_y; if (((x_pos == -1) || (x_pos == m_xScrollPosition)) &&
ViewStart (&old_x, &old_y); ((y_pos == -1) || (y_pos == m_yScrollPosition))) return;
if (((x_pos == -1) || (x_pos == old_x)) && ((y_pos == -1) || (y_pos == old_y)))
return;
if (x_pos > -1) int w, h;
GetClientSize(&w, &h);
if (x_pos != -1)
{ {
m_xScrollPosition = x_pos; 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; 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(); Refresh();
#ifdef __WXMSW__ #ifdef __WXMSW__
::UpdateWindow ((HWND) GetHWND()); ::UpdateWindow ((HWND) GetHWND());
#endif #endif

View File

@@ -2001,34 +2001,29 @@ void wxWindow::SetCursor( const wxCursor &cursor )
void wxWindow::Refresh( bool eraseBackground, const wxRect *rect ) 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 (eraseBackground && m_wxwindow && m_wxwindow->window)
{ {
if (rect) if (rect)
{
gdk_window_clear_area( m_wxwindow->window, gdk_window_clear_area( m_wxwindow->window,
rect->x, rect->x, rect->y,
rect->y,
rect->width, rect->width,
rect->height ); rect->height );
}
else else
{
Clear(); Clear();
} }
}
if (!rect) if (!rect)
{ {
if (m_wxwindow) if (m_wxwindow)
{ gtk_widget_draw( m_wxwindow, (GdkRectangle*) NULL );
int w = 0; else
int h = 0; gtk_widget_draw( m_widget, (GdkRectangle*) NULL );
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 );
}
} }
else else
{ {

View File

@@ -2001,34 +2001,29 @@ void wxWindow::SetCursor( const wxCursor &cursor )
void wxWindow::Refresh( bool eraseBackground, const wxRect *rect ) 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 (eraseBackground && m_wxwindow && m_wxwindow->window)
{ {
if (rect) if (rect)
{
gdk_window_clear_area( m_wxwindow->window, gdk_window_clear_area( m_wxwindow->window,
rect->x, rect->x, rect->y,
rect->y,
rect->width, rect->width,
rect->height ); rect->height );
}
else else
{
Clear(); Clear();
} }
}
if (!rect) if (!rect)
{ {
if (m_wxwindow) if (m_wxwindow)
{ gtk_widget_draw( m_wxwindow, (GdkRectangle*) NULL );
int w = 0; else
int h = 0; gtk_widget_draw( m_widget, (GdkRectangle*) NULL );
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 );
}
} }
else else
{ {