\membersection{wxWindow::ScrollLines}\label{wxwindowscrolllines}
-\func{virtual void}{ScrollLines}{\param{int }{lines}}
+\func{virtual bool}{ScrollLines}{\param{int }{lines}}
Scrolls the window by the given number of lines down (if {\it lines} is
positive) or up.
-This function is currently only implemented under MSW.
+\wxheading{Return value}
+
+Returns {\tt TRUE} if the window was scrolled, {\tt FALSE} if it was already
+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).
\wxheading{See also}
\membersection{wxWindow::ScrollPages}\label{wxwindowscrollpages}
-\func{virtual void}{ScrollPages}{\param{int }{pages}}
+\func{virtual bool}{ScrollPages}{\param{int }{pages}}
Scrolls the window by the given number of pages down (if {\it pages} is
positive) or up.
-This function is currently only implemented under MSW.
+\wxheading{Return value}
+
+Returns {\tt TRUE} if the window was scrolled, {\tt FALSE} if it was already
+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).
\wxheading{See also}
virtual void Freeze();
virtual void Thaw();
+ // textctrl specific scrolling
+ virtual bool ScrollLines(int lines);
+ virtual bool ScrollPages(int pages);
+
// wxGTK-specific: called recursively by Enable,
// to give widgets an oppprtunity to correct their colours after they
// have been changed by Enable
// 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);
+
private:
// change the font for everything in this control
void ChangeFontGlobally();
virtual void Freeze();
virtual void Thaw();
+ // textctrl specific scrolling
+ virtual bool ScrollLines(int lines);
+ virtual bool ScrollPages(int pages);
+
// wxGTK-specific: called recursively by Enable,
// to give widgets an oppprtunity to correct their colours after they
// have been changed by Enable
// 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);
+
private:
// change the font for everything in this control
void ChangeFontGlobally();
virtual void ScrollWindow( int dx, int dy,
const wxRect* rect = (wxRect *) NULL );
- virtual void ScrollLines(int lines);
- virtual void ScrollPages(int pages);
+ virtual bool ScrollLines(int lines);
+ virtual bool ScrollPages(int pages);
#if wxUSE_DRAG_AND_DROP
virtual void SetDropTarget( wxDropTarget *dropTarget );
const wxRect* rect = (wxRect *) NULL ) = 0;
// scrolls window by line/page: note that not all controls support this
- virtual void ScrollLines(int WXUNUSED(lines)) { }
- virtual void ScrollPages(int WXUNUSED(pages)) { }
-
- void LineUp() { ScrollLines(-1); }
- void LineDown() { ScrollLines(1); }
- void PageUp() { ScrollPages(-1); }
- void PageDown() { ScrollPages(1); }
+ //
+ // return TRUE if the position changed, FALSE otherwise
+ virtual bool ScrollLines(int WXUNUSED(lines)) { return FALSE; }
+ virtual bool ScrollPages(int WXUNUSED(pages)) { return FALSE; }
+
+ // convenient wrappers for ScrollLines/Pages
+ bool LineUp() { return ScrollLines(-1); }
+ bool LineDown() { return ScrollLines(1); }
+ bool PageUp() { return ScrollPages(-1); }
+ bool PageDown() { return ScrollPages(1); }
// context-sensitive help
// ----------------------
return wxSize(80, ret.y);
}
+// ----------------------------------------------------------------------------
+// freeze/thaw
+// ----------------------------------------------------------------------------
+
void wxTextCtrl::Freeze()
{
if ( HasFlag(wxTE_MULTILINE) )
gtk_text_thaw(GTK_TEXT(m_text));
}
}
+
+// ----------------------------------------------------------------------------
+// scrolling
+// ----------------------------------------------------------------------------
+
+GtkAdjustment *wxTextCtrl::GetVAdj() const
+{
+ return HasFlag(wxTE_MULTILINE) ? GTK_TEXT(m_text)->vadj : NULL;
+}
+
+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_signal_emit_by_name(GTK_OBJECT(adj), "value_changed");
+
+ return TRUE;
+}
+
+bool wxTextCtrl::ScrollLines(int lines)
+{
+ GtkAdjustment *adj = GetVAdj();
+ if ( !adj )
+ return FALSE;
+
+ // 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);
+}
+
+bool wxTextCtrl::ScrollPages(int pages)
+{
+ GtkAdjustment *adj = GetVAdj();
+ if ( !adj )
+ return FALSE;
+
+ return DoScroll(adj, pages*adj->page_increment);
+}
+
return wxSize(80, ret.y);
}
+// ----------------------------------------------------------------------------
+// freeze/thaw
+// ----------------------------------------------------------------------------
+
void wxTextCtrl::Freeze()
{
if ( HasFlag(wxTE_MULTILINE) )
gtk_text_thaw(GTK_TEXT(m_text));
}
}
+
+// ----------------------------------------------------------------------------
+// scrolling
+// ----------------------------------------------------------------------------
+
+GtkAdjustment *wxTextCtrl::GetVAdj() const
+{
+ return HasFlag(wxTE_MULTILINE) ? GTK_TEXT(m_text)->vadj : NULL;
+}
+
+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_signal_emit_by_name(GTK_OBJECT(adj), "value_changed");
+
+ return TRUE;
+}
+
+bool wxTextCtrl::ScrollLines(int lines)
+{
+ GtkAdjustment *adj = GetVAdj();
+ if ( !adj )
+ return FALSE;
+
+ // 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);
+}
+
+bool wxTextCtrl::ScrollPages(int pages)
+{
+ GtkAdjustment *adj = GetVAdj();
+ if ( !adj )
+ return FALSE;
+
+ return DoScroll(adj, pages*adj->page_increment);
+}
+
#endif // WXWIN_COMPATIBILITY
+inline int GetScrollPosition(HWND hWnd, int wOrient)
+{
+#ifdef __WXMICROWIN__
+ return ::GetScrollPosWX(hWnd, wOrient);
+#else
+ return ::GetScrollPos(hWnd, wOrient);
+#endif
+}
+
int wxWindowMSW::GetScrollPos(int orient) const
{
int wOrient;
wOrient = SB_HORZ;
else
wOrient = SB_VERT;
+
HWND hWnd = GetHwnd();
- if ( hWnd )
- {
-#ifdef __WXMICROWIN__
- return ::GetScrollPosWX(hWnd, wOrient);
-#else
- return ::GetScrollPos(hWnd, wOrient);
-#endif
- }
- else
- return 0;
+ wxCHECK_MSG( hWnd, 0, _T("no HWND in GetScrollPos") );
+
+ return GetScrollPosition(hWnd, wOrient);
}
// This now returns the whole range, not just the number
::ScrollWindow(GetHwnd(), dx, dy, prect ? &rect : NULL, NULL);
}
-static void ScrollVertically(HWND hwnd, int kind, int count)
+static bool ScrollVertically(HWND hwnd, int kind, int count)
{
+ int posStart = GetScrollPosition(hwnd, SB_VERT);
+
+ int pos = posStart;
for ( int n = 0; n < count; n++ )
{
::SendMessage(hwnd, WM_VSCROLL, kind, 0);
+
+ int posNew = GetScrollPosition(hwnd, SB_VERT);
+ if ( posNew == pos )
+ {
+ // don't bother to continue, we're already at top/bottom
+ break;
+ }
+
+ pos = posNew;
}
+
+ return pos != posStart;
}
-void wxWindowMSW::ScrollLines(int lines)
+bool wxWindowMSW::ScrollLines(int lines)
{
bool down = lines > 0;
- ScrollVertically(GetHwnd(),
- down ? SB_LINEDOWN : SB_LINEUP,
- down ? lines : -lines);
+ return ScrollVertically(GetHwnd(),
+ down ? SB_LINEDOWN : SB_LINEUP,
+ down ? lines : -lines);
}
-void wxWindowMSW::ScrollPages(int pages)
+bool wxWindowMSW::ScrollPages(int pages)
{
bool down = pages > 0;
- ScrollVertically(GetHwnd(),
- down ? SB_PAGEDOWN : SB_PAGEUP,
- down ? pages : -pages);
+ return ScrollVertically(GetHwnd(),
+ down ? SB_PAGEDOWN : SB_PAGEUP,
+ down ? pages : -pages);
}
// ---------------------------------------------------------------------------