1. made ScrollLines/Pages return bool indicating if we scrolled till the
end or not 2. implemented them for wxGTK text ctrl git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@11215 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1807,12 +1807,21 @@ implements the following methods:\par
|
||||
|
||||
\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}
|
||||
|
||||
@@ -1820,12 +1829,21 @@ This function is currently only implemented under MSW.
|
||||
|
||||
\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}
|
||||
|
||||
|
@@ -148,6 +148,10 @@ public:
|
||||
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
|
||||
@@ -159,6 +163,13 @@ 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);
|
||||
|
||||
private:
|
||||
// change the font for everything in this control
|
||||
void ChangeFontGlobally();
|
||||
|
@@ -148,6 +148,10 @@ public:
|
||||
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
|
||||
@@ -159,6 +163,13 @@ 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);
|
||||
|
||||
private:
|
||||
// change the font for everything in this control
|
||||
void ChangeFontGlobally();
|
||||
|
@@ -118,8 +118,8 @@ public:
|
||||
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 );
|
||||
|
@@ -664,13 +664,16 @@ public:
|
||||
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)) { }
|
||||
//
|
||||
// return TRUE if the position changed, FALSE otherwise
|
||||
virtual bool ScrollLines(int WXUNUSED(lines)) { return FALSE; }
|
||||
virtual bool ScrollPages(int WXUNUSED(pages)) { return FALSE; }
|
||||
|
||||
void LineUp() { ScrollLines(-1); }
|
||||
void LineDown() { ScrollLines(1); }
|
||||
void PageUp() { ScrollPages(-1); }
|
||||
void PageDown() { ScrollPages(1); }
|
||||
// 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
|
||||
// ----------------------
|
||||
|
@@ -1296,6 +1296,10 @@ wxSize wxTextCtrl::DoGetBestSize() const
|
||||
return wxSize(80, ret.y);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// freeze/thaw
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void wxTextCtrl::Freeze()
|
||||
{
|
||||
if ( HasFlag(wxTE_MULTILINE) )
|
||||
@@ -1311,3 +1315,59 @@ void wxTextCtrl::Thaw()
|
||||
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);
|
||||
}
|
||||
|
||||
|
@@ -1296,6 +1296,10 @@ wxSize wxTextCtrl::DoGetBestSize() const
|
||||
return wxSize(80, ret.y);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// freeze/thaw
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void wxTextCtrl::Freeze()
|
||||
{
|
||||
if ( HasFlag(wxTE_MULTILINE) )
|
||||
@@ -1311,3 +1315,59 @@ void wxTextCtrl::Thaw()
|
||||
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);
|
||||
}
|
||||
|
||||
|
@@ -770,6 +770,15 @@ int wxWindowMSW::GetScrollPage(int orient) const
|
||||
|
||||
#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;
|
||||
@@ -777,17 +786,11 @@ int wxWindowMSW::GetScrollPos(int orient) const
|
||||
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
|
||||
@@ -940,28 +943,42 @@ void wxWindowMSW::ScrollWindow(int dx, int dy, const wxRect *prect)
|
||||
::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(),
|
||||
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(),
|
||||
return ScrollVertically(GetHwnd(),
|
||||
down ? SB_PAGEDOWN : SB_PAGEUP,
|
||||
down ? pages : -pages);
|
||||
}
|
||||
|
Reference in New Issue
Block a user