X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9e691f46b2ec1b5dbbff2e51131e3c532e688a89..e7300ec6d9ebbd1cfa2fcf12c0ce6e5aee85a152:/src/gtk/scrolwin.cpp diff --git a/src/gtk/scrolwin.cpp b/src/gtk/scrolwin.cpp index 1d2378e79b..fe7bf353ea 100644 --- a/src/gtk/scrolwin.cpp +++ b/src/gtk/scrolwin.cpp @@ -33,6 +33,7 @@ #include "wx/scrolwin.h" #include "wx/panel.h" +#include "wx/sizer.h" #include "wx/gtk/private.h" #include "wx/gtk/win_gtk.h" @@ -275,13 +276,13 @@ bool wxScrolledWindow::Create(wxWindow *parent, m_vAdjust->upper = 1.0; m_vAdjust->value = 0.0; m_vAdjust->step_increment = 1.0; - m_vAdjust->page_increment = 1.0; + m_vAdjust->page_increment = 2.0; gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust), "changed" ); m_hAdjust->lower = 0.0; m_hAdjust->upper = 1.0; m_hAdjust->value = 0.0; m_hAdjust->step_increment = 1.0; - m_hAdjust->page_increment = 1.0; + m_hAdjust->page_increment = 2.0; gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust), "changed" ); // Handlers for new scrollbar values @@ -308,7 +309,7 @@ bool wxScrolledWindow::Create(wxWindow *parent, if (m_parent) m_parent->DoAddChild( this ); - + m_focusWidget = m_wxwindow; PostCreation(); @@ -332,7 +333,7 @@ void wxScrolledWindow::SetScrollbars (int pixelsPerUnitX, int pixelsPerUnitY, { int old_x = m_xScrollPixelsPerLine * m_xScrollPosition; int old_y = m_yScrollPixelsPerLine * m_yScrollPosition; - + m_xScrollPixelsPerLine = pixelsPerUnitX; m_yScrollPixelsPerLine = pixelsPerUnitY; m_xScrollLines = noUnitsX; @@ -351,14 +352,14 @@ void wxScrolledWindow::SetScrollbars (int pixelsPerUnitX, int pixelsPerUnitY, m_vAdjust->value = yPos; m_vAdjust->step_increment = 1.0; m_vAdjust->page_increment = 2.0; - + AdjustScrollbars(); - + if (!noRefresh) { int new_x = m_xScrollPixelsPerLine * m_xScrollPosition; int new_y = m_yScrollPixelsPerLine * m_yScrollPosition; - + m_targetWindow->ScrollWindow( old_x-new_x, old_y-new_y ); } } @@ -369,15 +370,53 @@ void wxScrolledWindow::AdjustScrollbars() m_targetWindow->GetClientSize( &w, &h ); if (m_xScrollPixelsPerLine == 0) + { + m_hAdjust->upper = 1.0; m_hAdjust->page_size = 1.0; + } else + { m_hAdjust->page_size = (w / m_xScrollPixelsPerLine); + int max = (int)(m_hAdjust->upper - m_hAdjust->page_size + 0.5); + if (max < 0) max = 0; + + int x_pos = m_xScrollPosition; + if (x_pos > max) x_pos = max; + if (x_pos < 0) x_pos = 0; + + int old_x = m_xScrollPosition; + m_xScrollPosition = x_pos; + m_hAdjust->value = x_pos; + + if (x_pos != old_x) + m_targetWindow->ScrollWindow( (old_x-m_xScrollPosition)*m_xScrollPixelsPerLine, 0 ); + } + if (m_yScrollPixelsPerLine == 0) + { + m_vAdjust->upper = 1.0; m_vAdjust->page_size = 1.0; + } else + { m_vAdjust->page_size = (h / m_yScrollPixelsPerLine); + int max = (int)(m_vAdjust->upper - m_vAdjust->page_size + 0.5); + if (max < 0) max = 0; + + int y_pos = m_yScrollPosition; + if (y_pos > max) y_pos = max; + if (y_pos < 0) y_pos = 0; + + int old_y = m_yScrollPosition; + m_yScrollPosition = y_pos; + m_vAdjust->value = y_pos; + + if (y_pos != old_y) + m_targetWindow->ScrollWindow( 0, (old_y-m_yScrollPosition)*m_yScrollPixelsPerLine ); + } + m_xScrollLinesPerPage = (int)(m_hAdjust->page_size + 0.5); m_yScrollLinesPerPage = (int)(m_vAdjust->page_size + 0.5); @@ -572,10 +611,24 @@ void wxScrolledWindow::EnableScrolling (bool x_scroll, bool y_scroll) void wxScrolledWindow::GetVirtualSize (int *x, int *y) const { + wxSize sz(0, 0); + if (m_targetWindow) + sz = m_targetWindow->GetClientSize(); + if ( x ) - *x = m_xScrollPixelsPerLine * m_xScrollLines; + { + if (m_xScrollPixelsPerLine == 0) + *x = sz.x; + else + *x = m_xScrollPixelsPerLine * m_xScrollLines; + } if ( y ) - *y = m_yScrollPixelsPerLine * m_yScrollLines; + { + if (m_yScrollPixelsPerLine == 0) + *y = sz.y; + else + *y = m_yScrollPixelsPerLine * m_yScrollLines; + } } // Where the current view starts from @@ -587,7 +640,7 @@ void wxScrolledWindow::GetViewStart (int *x, int *y) const *y = m_yScrollPosition; } -void wxScrolledWindow::CalcScrolledPosition(int x, int y, int *xx, int *yy) const +void wxScrolledWindow::DoCalcScrolledPosition(int x, int y, int *xx, int *yy) const { if ( xx ) *xx = x - m_xScrollPosition * m_xScrollPixelsPerLine; @@ -595,7 +648,7 @@ void wxScrolledWindow::CalcScrolledPosition(int x, int y, int *xx, int *yy) cons *yy = y - m_yScrollPosition * m_yScrollPixelsPerLine; } -void wxScrolledWindow::CalcUnscrolledPosition(int x, int y, int *xx, int *yy) const +void wxScrolledWindow::DoCalcUnscrolledPosition(int x, int y, int *xx, int *yy) const { if ( xx ) *xx = x + m_xScrollPosition * m_xScrollPixelsPerLine; @@ -760,6 +813,22 @@ void wxScrolledWindow::GtkVDisconnectEvent() (GtkSignalFunc) gtk_scrolled_window_vscroll_callback, (gpointer) this ); } + +bool wxScrolledWindow::Layout() +{ + if (GetSizer()) + { + // Take into account the virtual size and scrolled position of the window + int x, y, w, h; + CalcScrolledPosition(0,0, &x,&y); + GetVirtualSize(&w, &h); + GetSizer()->SetDimension(x, y, w, h); + return TRUE; + } + else + return wxPanel::Layout(); // fall back to default for LayoutConstraints +} + // ---------------------------------------------------------------------------- // event handlers // ----------------------------------------------------------------------------