From 0c131a5ad27be67aa6d859ee31024dac9885a753 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 9 Feb 2006 03:53:34 +0000 Subject: [PATCH] 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 --- docs/changes.txt | 1 + docs/latex/wx/window.tex | 4 +-- include/wx/gtk/textctrl.h | 11 ------- include/wx/gtk/window.h | 6 ++++ src/gtk/scrolbar.cpp | 4 +++ src/gtk/textctrl.cpp | 61 ++------------------------------------- src/gtk/window.cpp | 33 +++++++++++++++++++++ 7 files changed, 48 insertions(+), 72 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index f7f576ea4d..39ca9398b7 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -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: diff --git a/docs/latex/wx/window.tex b/docs/latex/wx/window.tex index af197e2269..f4e551cff2 100644 --- a/docs/latex/wx/window.tex +++ b/docs/latex/wx/window.tex @@ -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} diff --git a/include/wx/gtk/textctrl.h b/include/wx/gtk/textctrl.h index b912909563..e2041cb963 100644 --- a/include/wx/gtk/textctrl.h +++ b/include/wx/gtk/textctrl.h @@ -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; } diff --git a/include/wx/gtk/window.h b/include/wx/gtk/window.h index 9b0c3d9aba..c14e0d836e 100644 --- a/include/wx/gtk/window.h +++ b/include/wx/gtk/window.h @@ -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) diff --git a/src/gtk/scrolbar.cpp b/src/gtk/scrolbar.cpp index 91895aab94..3a44d755f0 100644 --- a/src/gtk/scrolbar.cpp +++ b/src/gtk/scrolbar.cpp @@ -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); diff --git a/src/gtk/textctrl.cpp b/src/gtk/textctrl.cpp index 74425264af..d36c312925 100644 --- a/src/gtk/textctrl.cpp +++ b/src/gtk/textctrl.cpp @@ -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)) diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index 43673380dc..e573871d0d 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -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 ) { -- 2.45.2