implemented ScrollLines/Pages() for all classes in wxGTK, not just wxTextCtrl (patch 1281503)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@37407 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2006-02-09 03:53:34 +00:00
parent a8e24848f6
commit 0c131a5ad2
7 changed files with 48 additions and 72 deletions

View File

@@ -136,6 +136,7 @@ wxGTK:
- Worked around pango crashes in strncmp on Solaris 10.
- Polygon and line drawing speeded up if there is no scaling.
- Fixed problems with CJK input method.
- Implemented ScrollLines/Pages() for all windows (Paul Cornett)
wxMac:

View File

@@ -2404,9 +2404,7 @@ on top/bottom and nothing was done.
\wxheading{Remarks}
This function is currently only implemented under MSW and wxTextCtrl under
wxGTK (it also works for wxScrolledWindow derived classes under all
platforms).
This function is currently only implemented under MSW and wxGTK.
\wxheading{See also}

View File

@@ -151,10 +151,6 @@ public:
virtual void Freeze();
virtual void Thaw();
// textctrl specific scrolling
virtual bool ScrollLines(int lines);
virtual bool ScrollPages(int pages);
// implementation only from now on
// wxGTK-specific: called recursively by Enable,
@@ -178,13 +174,6 @@ protected:
// common part of all ctors
void Init();
// get the vertical adjustment, if any, NULL otherwise
GtkAdjustment *GetVAdj() const;
// scroll the control by the given number of pixels, return true if the
// scroll position changed
bool DoScroll(GtkAdjustment *adj, int diff);
// Widgets that use the style->base colour for the BG colour should
// override this and return true.
virtual bool UseGTKStyleBase() const { return true; }

View File

@@ -99,6 +99,8 @@ public:
virtual int GetScrollRange( int orient ) const;
virtual void ScrollWindow( int dx, int dy,
const wxRect* rect = (wxRect *) NULL );
virtual bool ScrollLines(int lines);
virtual bool ScrollPages(int pages);
#if wxUSE_DRAG_AND_DROP
virtual void SetDropTarget( wxDropTarget *dropTarget );
@@ -268,6 +270,10 @@ protected:
// ApplyWidgetStyle -- override this, not ApplyWidgetStyle
virtual void DoApplyWidgetStyle(GtkRcStyle *style);
protected:
// GtkAdjustment to be used by Scroll{Lines,Pages}
void SetVScrollAdjustment(GtkAdjustment* adj);
private:
DECLARE_DYNAMIC_CLASS(wxWindowGTK)
DECLARE_NO_COPY_CLASS(wxWindowGTK)

View File

@@ -186,6 +186,10 @@ bool wxScrollBar::Create(wxWindow *parent, wxWindowID id,
m_widget = gtk_hscrollbar_new( (GtkAdjustment *) NULL );
m_adjust = gtk_range_get_adjustment( GTK_RANGE(m_widget) );
if ( style & wxSB_VERTICAL )
{
SetVScrollAdjustment(m_adjust);
}
g_signal_connect (m_adjust, "value_changed",
G_CALLBACK (gtk_scrollbar_callback), this);

View File

@@ -618,7 +618,10 @@ bool wxTextCtrl::Create( wxWindow *parent,
PostCreation(size);
if (multi_line)
{
gtk_widget_show(m_text);
SetVScrollAdjustment(gtk_scrolled_window_get_vadjustment((GtkScrolledWindow*)m_widget));
}
if (!value.empty())
{
@@ -1704,64 +1707,6 @@ void wxTextCtrl::OnUrlMouseEvent(wxMouseEvent& event)
GetEventHandler()->ProcessEvent(url_event);
}
// ----------------------------------------------------------------------------
// scrolling
// ----------------------------------------------------------------------------
GtkAdjustment *wxTextCtrl::GetVAdj() const
{
if ( !IsMultiLine() )
return NULL;
return gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(m_widget));
}
bool wxTextCtrl::DoScroll(GtkAdjustment *adj, int diff)
{
float value = adj->value + diff;
if ( value < 0 )
value = 0;
float upper = adj->upper - adj->page_size;
if ( value > upper )
value = upper;
// did we noticeably change the scroll position?
if ( fabs(adj->value - value) < 0.2 )
{
// well, this is what Robert does in wxScrollBar, so it must be good...
return false;
}
adj->value = value;
gtk_adjustment_value_changed(GTK_ADJUSTMENT(adj));
return true;
}
bool wxTextCtrl::ScrollLines(int lines)
{
GtkAdjustment *adj = GetVAdj();
if ( !adj )
return false;
int diff = (int)ceil(lines*adj->step_increment);
return DoScroll(adj, diff);
}
bool wxTextCtrl::ScrollPages(int pages)
{
GtkAdjustment *adj = GetVAdj();
if ( !adj )
return false;
return DoScroll(adj, (int)ceil(pages*adj->page_increment));
}
// static
wxVisualAttributes
wxTextCtrl::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))

View File

@@ -3652,6 +3652,39 @@ void wxWindowGTK::WarpPointer( int x, int y )
gdk_window_warp_pointer( window, x, y );
}
static bool wxScrollAdjust(GtkAdjustment* adj, double change)
{
double value_start = adj->value;
double value = value_start + change;
double upper = adj->upper - adj->page_size;
if (value > upper)
{
value = upper;
}
// Lower bound will be checked by gtk_adjustment_set_value
gtk_adjustment_set_value(adj, value);
return adj->value != value_start;
}
bool wxWindowGTK::ScrollLines(int lines)
{
return
m_vAdjust != NULL &&
wxScrollAdjust(m_vAdjust, lines * m_vAdjust->step_increment);
}
bool wxWindowGTK::ScrollPages(int pages)
{
return
m_vAdjust != NULL &&
wxScrollAdjust(m_vAdjust, pages * m_vAdjust->page_increment);
}
void wxWindowGTK::SetVScrollAdjustment(GtkAdjustment* adj)
{
wxASSERT(m_vAdjust == NULL);
m_vAdjust = adj;
}
void wxWindowGTK::Refresh( bool eraseBackground, const wxRect *rect )
{