From 1ce52aa64b0d54ec3eb5adbbe1c7c825149d3f41 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 23 Jul 2004 21:32:44 +0000 Subject: [PATCH] implemented ScrollLines/Pages() for GTK+ 2 git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@28441 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + src/gtk/textctrl.cpp | 29 +++++++++++++++-------------- src/gtk1/textctrl.cpp | 29 +++++++++++++++-------------- 3 files changed, 31 insertions(+), 28 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 9f7158bd61..3475096c43 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -231,6 +231,7 @@ wxGTK: - fixed many rendering artifacts and wrong colours with lots of GTK+ themes - implemented wxColourDialog as native dialog - implemented wxTextCtrl::HitTest() (GTK+ >= 2) +- implemented wxTextCtrl::ScrollLines() and ScrollPages for GTK+ 2.x - wxTreeCtrl::GetCount() counts root as well now (compatible with MSW) - added support for wxCHK_3STATE style (GTK2 only) - implemented text underlining under GTK2 diff --git a/src/gtk/textctrl.cpp b/src/gtk/textctrl.cpp index 4f48c8f5cd..50783a1b0d 100644 --- a/src/gtk/textctrl.cpp +++ b/src/gtk/textctrl.cpp @@ -1718,16 +1718,18 @@ void wxTextCtrl::Thaw() GtkAdjustment *wxTextCtrl::GetVAdj() const { + if ( !IsMultiLine() ) + return NULL; + #ifdef __WXGTK20__ - return NULL; + return gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(m_widget)); #else - return HasFlag(wxTE_MULTILINE) ? GTK_TEXT(m_text)->vadj : NULL; + return GTK_TEXT(m_text)->vadj; #endif } bool wxTextCtrl::DoScroll(GtkAdjustment *adj, int diff) { -#ifndef __WXGTK20__ float value = adj->value + diff; if ( value < 0 ) @@ -1746,39 +1748,38 @@ bool wxTextCtrl::DoScroll(GtkAdjustment *adj, int diff) adj->value = value; +#ifdef __WXGTK20__ + gtk_adjustment_value_changed(GTK_ADJUSTMENT(adj)); +#else gtk_signal_emit_by_name(GTK_OBJECT(adj), "value_changed"); - #endif + return TRUE; } bool wxTextCtrl::ScrollLines(int lines) { -#ifdef __WXGTK20__ - return FALSE; -#else GtkAdjustment *adj = GetVAdj(); if ( !adj ) return FALSE; +#ifdef __WXGTK20__ + int diff = (int)ceil(lines*adj->step_increment); +#else // this is hardcoded to 10 in GTK+ 1.2 (great idea) - static const int KEY_SCROLL_PIXELS = 10; - - return DoScroll(adj, lines*KEY_SCROLL_PIXELS); + int diff = 10*lines; #endif + + return DoScroll(adj, diff); } bool wxTextCtrl::ScrollPages(int pages) { -#ifdef __WXGTK20__ - return FALSE; -#else GtkAdjustment *adj = GetVAdj(); if ( !adj ) return FALSE; return DoScroll(adj, (int)ceil(pages*adj->page_increment)); -#endif } diff --git a/src/gtk1/textctrl.cpp b/src/gtk1/textctrl.cpp index 4f48c8f5cd..50783a1b0d 100644 --- a/src/gtk1/textctrl.cpp +++ b/src/gtk1/textctrl.cpp @@ -1718,16 +1718,18 @@ void wxTextCtrl::Thaw() GtkAdjustment *wxTextCtrl::GetVAdj() const { + if ( !IsMultiLine() ) + return NULL; + #ifdef __WXGTK20__ - return NULL; + return gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(m_widget)); #else - return HasFlag(wxTE_MULTILINE) ? GTK_TEXT(m_text)->vadj : NULL; + return GTK_TEXT(m_text)->vadj; #endif } bool wxTextCtrl::DoScroll(GtkAdjustment *adj, int diff) { -#ifndef __WXGTK20__ float value = adj->value + diff; if ( value < 0 ) @@ -1746,39 +1748,38 @@ bool wxTextCtrl::DoScroll(GtkAdjustment *adj, int diff) adj->value = value; +#ifdef __WXGTK20__ + gtk_adjustment_value_changed(GTK_ADJUSTMENT(adj)); +#else gtk_signal_emit_by_name(GTK_OBJECT(adj), "value_changed"); - #endif + return TRUE; } bool wxTextCtrl::ScrollLines(int lines) { -#ifdef __WXGTK20__ - return FALSE; -#else GtkAdjustment *adj = GetVAdj(); if ( !adj ) return FALSE; +#ifdef __WXGTK20__ + int diff = (int)ceil(lines*adj->step_increment); +#else // this is hardcoded to 10 in GTK+ 1.2 (great idea) - static const int KEY_SCROLL_PIXELS = 10; - - return DoScroll(adj, lines*KEY_SCROLL_PIXELS); + int diff = 10*lines; #endif + + return DoScroll(adj, diff); } bool wxTextCtrl::ScrollPages(int pages) { -#ifdef __WXGTK20__ - return FALSE; -#else GtkAdjustment *adj = GetVAdj(); if ( !adj ) return FALSE; return DoScroll(adj, (int)ceil(pages*adj->page_increment)); -#endif } -- 2.45.2