scrollbar handling simplification

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@39178 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Paul Cornett
2006-05-17 04:54:13 +00:00
parent 69555b5c86
commit add7cadd99
9 changed files with 295 additions and 600 deletions

View File

@@ -2896,6 +2896,7 @@ typedef struct _GtkAccelGroup GtkAccelGroup;
typedef struct _GtkItemFactory GtkItemFactory; typedef struct _GtkItemFactory GtkItemFactory;
typedef struct _GtkSelectionData GtkSelectionData; typedef struct _GtkSelectionData GtkSelectionData;
typedef struct _GtkTextBuffer GtkTextBuffer; typedef struct _GtkTextBuffer GtkTextBuffer;
typedef struct _GtkRange GtkRange;
typedef GtkWidget *WXWidget; typedef GtkWidget *WXWidget;

View File

@@ -100,47 +100,6 @@ private:
DECLARE_NO_COPY_CLASS(wxGtkString) DECLARE_NO_COPY_CLASS(wxGtkString)
}; };
//-----------------------------------------------------------------------------
// GTK+ scroll types -> wxEventType
//-----------------------------------------------------------------------------
// translate a GTK+ scroll type to a wxEventType
inline wxEventType GtkScrollTypeToWx(guint scrollType)
{
wxEventType command;
switch ( scrollType )
{
case GTK_SCROLL_STEP_BACKWARD:
command = wxEVT_SCROLL_LINEUP;
break;
case GTK_SCROLL_STEP_FORWARD:
command = wxEVT_SCROLL_LINEDOWN;
break;
case GTK_SCROLL_PAGE_BACKWARD:
command = wxEVT_SCROLL_PAGEUP;
break;
case GTK_SCROLL_PAGE_FORWARD:
command = wxEVT_SCROLL_PAGEDOWN;
break;
default:
command = wxEVT_SCROLL_THUMBTRACK;
}
return command;
}
inline wxEventType GtkScrollWinTypeToWx(guint scrollType)
{
// GtkScrollTypeToWx() returns SCROLL_XXX, not SCROLLWIN_XXX as we need
return GtkScrollTypeToWx(scrollType) +
wxEVT_SCROLLWIN_TOP - wxEVT_SCROLL_TOP;
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Misc. functions // Misc. functions
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View File

@@ -25,8 +25,7 @@ class WXDLLIMPEXP_CORE wxScrollBar;
class WXDLLIMPEXP_CORE wxScrollBar: public wxScrollBarBase class WXDLLIMPEXP_CORE wxScrollBar: public wxScrollBarBase
{ {
public: public:
wxScrollBar() wxScrollBar();
{ m_adjust = (GtkAdjustment *) NULL; m_oldPos = 0.0; }
inline wxScrollBar( wxWindow *parent, wxWindowID id, inline wxScrollBar( wxWindow *parent, wxWindowID id,
const wxPoint& pos = wxDefaultPosition, const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, const wxSize& size = wxDefaultSize,
@@ -49,19 +48,11 @@ public:
int GetRange() const; int GetRange() const;
virtual void SetThumbPosition( int viewStart ); virtual void SetThumbPosition( int viewStart );
virtual void SetScrollbar( int position, int thumbSize, int range, int pageSize, virtual void SetScrollbar( int position, int thumbSize, int range, int pageSize,
bool refresh = TRUE ); bool refresh = true );
// Backward compatibility void SetThumbSize(int thumbSize);
// ----------------------
int GetValue(void) const;
void SetValue( int viewStart );
void GetValues( int *viewStart, int *viewLength, int *objectLength, int *pageLength) const;
int GetViewLength() const;
int GetObjectLength() const;
void SetPageSize( int pageLength ); void SetPageSize( int pageLength );
void SetObjectLength( int objectLength ); void SetRange(int range);
void SetViewLength( int viewLength );
static wxVisualAttributes static wxVisualAttributes
GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
@@ -71,12 +62,6 @@ public:
bool IsOwnGtkWindow( GdkWindow *window ); bool IsOwnGtkWindow( GdkWindow *window );
GtkAdjustment *m_adjust;
float m_oldPos;
protected:
virtual wxSize DoGetBestSize() const;
private: private:
DECLARE_DYNAMIC_CLASS(wxScrollBar) DECLARE_DYNAMIC_CLASS(wxScrollBar)
}; };

View File

@@ -31,17 +31,15 @@ public:
protected: protected:
// this does (each) half of AdjustScrollbars() work // this does (each) half of AdjustScrollbars() work
void DoAdjustScrollbar(GtkAdjustment *adj, void DoAdjustScrollbar(GtkRange* range,
int pixelsPerLine, int pixelsPerLine,
int winSize, int winSize,
int virtSize, int virtSize,
int *pos,
int *lines, int *lines,
int *linesPerPage); int *linesPerPage);
// and this does the same for Scroll() // and this does the same for Scroll()
void DoScroll(int orient, void DoScroll(int orient,
GtkAdjustment *adj,
int pos, int pos,
int pixelsPerLine, int pixelsPerLine,
int *posOld); int *posOld);

View File

@@ -172,10 +172,6 @@ public:
virtual void ApplyToolTip( GtkTooltips *tips, const wxChar *tip ); virtual void ApplyToolTip( GtkTooltips *tips, const wxChar *tip );
#endif // wxUSE_TOOLTIPS #endif // wxUSE_TOOLTIPS
// Call after modifing the value of m_hAdjust or m_vAdjust to bring the
// scrolbar in sync (this does not generate any wx events)
void GtkUpdateScrollbar(int orient);
// Called from GTK signal handlers. it indicates that // Called from GTK signal handlers. it indicates that
// the layouting functions have to be called later on // the layouting functions have to be called later on
// (i.e. in idle time, implemented in OnInternalIdle() ). // (i.e. in idle time, implemented in OnInternalIdle() ).
@@ -192,6 +188,9 @@ public:
// is this a radiobutton (used by radiobutton code itself only)? // is this a radiobutton (used by radiobutton code itself only)?
virtual bool IsRadioButton() const { return false; } virtual bool IsRadioButton() const { return false; }
// Common scroll event handling code for wxWindow and wxScrollBar
wxEventType GetScrollEventType(GtkRange* range);
// position and size of the window // position and size of the window
int m_x, m_y; int m_x, m_y;
int m_width, m_height; int m_width, m_height;
@@ -206,10 +205,10 @@ public:
wxGtkIMData *m_imData; wxGtkIMData *m_imData;
// scrolling stuff // horizontal/vertical scroll bar
GtkAdjustment *m_hAdjust,*m_vAdjust; GtkRange* m_scrollBar[2];
float m_oldHorizontalPos; // horizontal/vertical scroll position
float m_oldVerticalPos; double m_scrollPos[2];
// extra (wxGTK-specific) flags // extra (wxGTK-specific) flags
bool m_needParent:1; // ! wxFrame, wxDialog, wxNotebookPage ? bool m_needParent:1; // ! wxFrame, wxDialog, wxNotebookPage ?
@@ -227,6 +226,8 @@ public:
// chain needs update // chain needs update
bool m_needsStyleChange:1; // May not be able to change bool m_needsStyleChange:1; // May not be able to change
// background style until OnIdle // background style until OnIdle
bool m_mouseButtonDown:1;
bool m_blockScrollEvent:1;
// C++ has no virtual methods in the constrcutor of any class but we need // C++ has no virtual methods in the constrcutor of any class but we need
// different methods of inserting a child window into a wxFrame, // different methods of inserting a child window into a wxFrame,
@@ -282,9 +283,8 @@ protected:
// sets the border of a given GtkScrolledWindow from a wx style // sets the border of a given GtkScrolledWindow from a wx style
static void GtkScrolledWindowSetBorder(GtkWidget* w, int style); static void GtkScrolledWindowSetBorder(GtkWidget* w, int style);
protected: void BlockScrollEvent();
// GtkAdjustment to be used by Scroll{Lines,Pages} void UnblockScrollEvent();
void SetVScrollAdjustment(GtkAdjustment* adj);
private: private:
DECLARE_DYNAMIC_CLASS(wxWindowGTK) DECLARE_DYNAMIC_CLASS(wxWindowGTK)

View File

@@ -18,135 +18,78 @@
#include "wx/utils.h" #include "wx/utils.h"
#endif #endif
#include "wx/math.h"
#include "wx/gtk/private.h" #include "wx/gtk/private.h"
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// data // "value_changed" from scrollbar
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
extern bool g_blockEventsOnDrag;
static wxEventType g_currentUpDownEvent = wxEVT_NULL;
static const float sensitivity = 0.02;
//-----------------------------------------------------------------------------
// "value_changed"
//-----------------------------------------------------------------------------
// FIXME: is GtkScrollType really passed to us as 2nd argument?
extern "C" { extern "C" {
static void gtk_scrollbar_callback( GtkAdjustment *adjust, static void
wxScrollBar *win ) gtk_value_changed(GtkRange* range, wxScrollBar* win)
{ {
if (g_isIdle) wxapp_install_idle_handler(); wxEventType eventType = win->GetScrollEventType(range);
if (eventType != wxEVT_NULL)
if (!win->m_hasVMT) return;
if (g_blockEventsOnDrag) return;
float diff = adjust->value - win->m_oldPos;
if (fabs(diff) < sensitivity) return;
win->m_oldPos = adjust->value;
wxEventType command = GtkScrollTypeToWx(GTK_SCROLL_JUMP);
double dvalue = adjust->value;
int value = (int)(dvalue < 0 ? dvalue - 0.5 : dvalue + 0.5);
int orient = win->HasFlag(wxSB_VERTICAL) ? wxVERTICAL : wxHORIZONTAL;
// throw a LINEUP / LINEDOWN event if necessary
if (g_currentUpDownEvent != wxEVT_NULL)
{ {
wxScrollEvent event( g_currentUpDownEvent, win->GetId(), value, orient ); const int orient = win->HasFlag(wxSB_VERTICAL) ? wxVERTICAL : wxHORIZONTAL;
event.SetEventObject( win ); const int value = win->GetThumbPosition();
win->GetEventHandler()->ProcessEvent( event ); wxScrollEvent event(eventType, win->GetId(), value, orient);
event.SetEventObject(win);
win->GetEventHandler()->ProcessEvent(event);
if (!win->m_isScrolling)
{
wxScrollEvent event(wxEVT_SCROLL_CHANGED, win->GetId(), value, orient);
event.SetEventObject(win);
win->GetEventHandler()->ProcessEvent(event);
}
} }
// throw other event (wxEVT_SCROLL_THUMBTRACK)
wxScrollEvent event( command, win->GetId(), value, orient );
event.SetEventObject( win );
win->GetEventHandler()->ProcessEvent( event );
/*
wxCommandEvent cevent( wxEVT_COMMAND_SCROLLBAR_UPDATED, win->GetId() );
cevent.SetEventObject( win );
win->ProcessEvent( cevent );
*/
} }
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// "button_press_event" from slider // "button_press_event" from scrollbar
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
extern "C" { extern "C" {
static gint gtk_scrollbar_button_press_callback( GtkRange *widget, static gboolean
GdkEventButton *gdk_event, gtk_button_press_event(GtkRange*, GdkEventButton*, wxScrollBar* win)
wxScrollBar *win )
{ {
if (g_isIdle) wxapp_install_idle_handler(); if (g_isIdle) wxapp_install_idle_handler();
// check if a LINEUP/LINEDOWN event must be thrown win->m_mouseButtonDown = true;
// I suppose here the size of scrollbar top/bottom buttons is 16px height return false;
if (gdk_event->type == GDK_BUTTON_PRESS && gdk_event->button == 1)
{
int scroll_height, mouse_pos;
// get the mouse position when the click is done
if (win->HasFlag(wxSB_VERTICAL))
{
scroll_height = GTK_WIDGET(widget)->allocation.height - 16;
mouse_pos = (int)gdk_event->y;
}
else
{
scroll_height = GTK_WIDGET(widget)->allocation.width - 16;
mouse_pos = (int)gdk_event->x;
}
// compare mouse position to scrollbar height
if (mouse_pos > scroll_height)
g_currentUpDownEvent = wxEVT_SCROLL_LINEDOWN;
else if (mouse_pos < 16)
g_currentUpDownEvent = wxEVT_SCROLL_LINEUP;
}
return FALSE;
} }
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// "button_release_event" from slider // "button_release_event" from scrollbar
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
extern "C" { extern "C" {
static gint static gboolean
gtk_scrollbar_button_release_callback( GtkRange *WXUNUSED(widget), gtk_button_release_event(GtkRange*, GdkEventButton*, wxScrollBar* win)
GdkEventButton *WXUNUSED(gdk_event),
wxScrollBar *win )
{ {
if (g_isIdle) if (g_isIdle)
wxapp_install_idle_handler(); wxapp_install_idle_handler();
win->m_mouseButtonDown = false;
// If thumb tracking
if (win->m_isScrolling) if (win->m_isScrolling)
{ {
wxEventType command = wxEVT_SCROLL_THUMBRELEASE; win->m_isScrolling = false;
int value = (int)ceil(win->m_adjust->value); const int value = win->GetThumbPosition();
int orient = win->HasFlag(wxSB_VERTICAL) ? wxVERTICAL : wxHORIZONTAL; const int orient = win->HasFlag(wxSB_VERTICAL) ? wxVERTICAL : wxHORIZONTAL;
wxScrollEvent event( command, win->GetId(), value, orient ); wxScrollEvent event(wxEVT_SCROLL_THUMBRELEASE, win->GetId(), value, orient);
event.SetEventObject( win ); event.SetEventObject(win);
win->GetEventHandler()->ProcessEvent( event ); win->GetEventHandler()->ProcessEvent(event);
wxScrollEvent event2(wxEVT_SCROLL_CHANGED, win->GetId(), value, orient);
event2.SetEventObject(win);
win->GetEventHandler()->ProcessEvent(event2);
} }
win->m_isScrolling = false; return false;
// reset the LINEUP/LINEDOWN flag when the mouse button is released
g_currentUpDownEvent = wxEVT_NULL;
return FALSE;
} }
} }
@@ -156,6 +99,10 @@ gtk_scrollbar_button_release_callback( GtkRange *WXUNUSED(widget),
IMPLEMENT_DYNAMIC_CLASS(wxScrollBar,wxControl) IMPLEMENT_DYNAMIC_CLASS(wxScrollBar,wxControl)
wxScrollBar::wxScrollBar()
{
}
wxScrollBar::~wxScrollBar() wxScrollBar::~wxScrollBar()
{ {
} }
@@ -174,27 +121,20 @@ bool wxScrollBar::Create(wxWindow *parent, wxWindowID id,
return false; return false;
} }
m_oldPos = 0.0; const bool isVertical = (style & wxSB_VERTICAL) != 0;
if (isVertical)
if ((style & wxSB_VERTICAL) == wxSB_VERTICAL)
m_widget = gtk_vscrollbar_new( (GtkAdjustment *) NULL ); m_widget = gtk_vscrollbar_new( (GtkAdjustment *) NULL );
else else
m_widget = gtk_hscrollbar_new( (GtkAdjustment *) NULL ); m_widget = gtk_hscrollbar_new( (GtkAdjustment *) NULL );
m_adjust = gtk_range_get_adjustment( GTK_RANGE(m_widget) ); m_scrollBar[int(isVertical)] = (GtkRange*)m_widget;
if ( style & wxSB_VERTICAL )
{
SetVScrollAdjustment(m_adjust);
}
g_signal_connect (m_adjust, "value_changed", g_signal_connect(m_widget, "value_changed",
G_CALLBACK (gtk_scrollbar_callback), this); G_CALLBACK(gtk_value_changed), this);
g_signal_connect (m_widget, "button_press_event", g_signal_connect(m_widget, "button_press_event",
G_CALLBACK (gtk_scrollbar_button_press_callback), G_CALLBACK(gtk_button_press_event), this);
this); g_signal_connect(m_widget, "button_release_event",
g_signal_connect (m_widget, "button_release_event", G_CALLBACK(gtk_button_release_event), this);
G_CALLBACK (gtk_scrollbar_button_release_callback),
this);
m_parent->DoAddChild( this ); m_parent->DoAddChild( this );
@@ -205,128 +145,63 @@ bool wxScrollBar::Create(wxWindow *parent, wxWindowID id,
int wxScrollBar::GetThumbPosition() const int wxScrollBar::GetThumbPosition() const
{ {
double val = m_adjust->value; GtkAdjustment* adj = ((GtkRange*)m_widget)->adjustment;
return (int)(val < 0 ? val - 0.5 : val + 0.5); return int(adj->value + 0.5);
} }
int wxScrollBar::GetThumbSize() const int wxScrollBar::GetThumbSize() const
{ {
return (int)(m_adjust->page_size+0.5); GtkAdjustment* adj = ((GtkRange*)m_widget)->adjustment;
return int(adj->page_size);
} }
int wxScrollBar::GetPageSize() const int wxScrollBar::GetPageSize() const
{ {
return (int)(m_adjust->page_increment+0.5); GtkAdjustment* adj = ((GtkRange*)m_widget)->adjustment;
return int(adj->page_increment);
} }
int wxScrollBar::GetRange() const int wxScrollBar::GetRange() const
{ {
return (int)(m_adjust->upper+0.5); GtkAdjustment* adj = ((GtkRange*)m_widget)->adjustment;
return int(adj->upper);
} }
void wxScrollBar::SetThumbPosition( int viewStart ) void wxScrollBar::SetThumbPosition( int viewStart )
{ {
if (m_isScrolling) return; if (GetThumbPosition() != viewStart)
float fpos = (float)viewStart;
m_oldPos = fpos;
if (fabs(fpos-m_adjust->value) < 0.2) return;
m_adjust->value = fpos;
g_signal_handlers_disconnect_by_func (m_adjust,
(gpointer) gtk_scrollbar_callback,
this);
g_signal_emit_by_name (m_adjust, "value_changed");
g_signal_connect (m_adjust, "value_changed",
G_CALLBACK (gtk_scrollbar_callback), this);
}
void wxScrollBar::SetScrollbar( int position, int thumbSize, int range, int pageSize,
bool WXUNUSED(refresh) )
{
float fpos = (float)position;
float frange = (float)range;
float fthumb = (float)thumbSize;
float fpage = (float)pageSize;
if ((fabs(frange-m_adjust->upper) < 0.2) &&
(fabs(fthumb-m_adjust->page_size) < 0.2) &&
(fabs(fpage-m_adjust->page_increment) < 0.2))
{ {
SetThumbPosition( position ); BlockScrollEvent();
return; gtk_range_set_value((GtkRange*)m_widget, viewStart);
UnblockScrollEvent();
GtkAdjustment* adj = ((GtkRange*)m_widget)->adjustment;
const int i = HasFlag(wxSB_VERTICAL);
m_scrollPos[i] = adj->value;
} }
m_oldPos = fpos;
m_adjust->lower = 0.0;
m_adjust->upper = frange;
m_adjust->value = fpos;
m_adjust->step_increment = 1.0;
m_adjust->page_increment = (float)(wxMax(fpage,0));
m_adjust->page_size = fthumb;
g_signal_emit_by_name (m_adjust, "changed");
} }
/* Backward compatibility */ void wxScrollBar::SetScrollbar(int position, int thumbSize, int range, int pageSize, bool)
int wxScrollBar::GetValue() const
{ {
return GetThumbPosition(); GtkAdjustment* adj = ((GtkRange*)m_widget)->adjustment;
} adj->value = position;
adj->step_increment = 1;
void wxScrollBar::SetValue( int viewStart ) adj->page_increment = pageSize;
{ adj->page_size = thumbSize;
SetThumbPosition( viewStart ); BlockScrollEvent();
} gtk_range_set_range((GtkRange*)m_widget, 0, range);
UnblockScrollEvent();
void wxScrollBar::GetValues( int *viewStart, int *viewLength, int *objectLength, int *pageLength ) const const int i = HasFlag(wxSB_VERTICAL);
{ m_scrollPos[i] = adj->value;
int pos = (int)(m_adjust->value+0.5);
int thumb = (int)(m_adjust->page_size+0.5);
int page = (int)(m_adjust->page_increment+0.5);
int range = (int)(m_adjust->upper+0.5);
*viewStart = pos;
*viewLength = range;
*objectLength = thumb;
*pageLength = page;
}
int wxScrollBar::GetViewLength() const
{
return (int)(m_adjust->upper+0.5);
}
int wxScrollBar::GetObjectLength() const
{
return (int)(m_adjust->page_size+0.5);
} }
void wxScrollBar::SetPageSize( int pageLength ) void wxScrollBar::SetPageSize( int pageLength )
{ {
int pos = (int)(m_adjust->value+0.5); SetScrollbar(GetThumbPosition(), GetThumbSize(), GetRange(), pageLength);
int thumb = (int)(m_adjust->page_size+0.5);
int range = (int)(m_adjust->upper+0.5);
SetScrollbar( pos, thumb, range, pageLength );
} }
void wxScrollBar::SetObjectLength( int objectLength ) void wxScrollBar::SetRange(int range)
{ {
int pos = (int)(m_adjust->value+0.5); SetScrollbar(GetThumbPosition(), GetThumbSize(), range, GetPageSize());
int page = (int)(m_adjust->page_increment+0.5);
int range = (int)(m_adjust->upper+0.5);
SetScrollbar( pos, objectLength, range, page );
}
void wxScrollBar::SetViewLength( int viewLength )
{
int pos = (int)(m_adjust->value+0.5);
int thumb = (int)(m_adjust->page_size+0.5);
int page = (int)(m_adjust->page_increment+0.5);
SetScrollbar( pos, thumb, viewLength, page );
} }
bool wxScrollBar::IsOwnGtkWindow( GdkWindow *window ) bool wxScrollBar::IsOwnGtkWindow( GdkWindow *window )
@@ -335,11 +210,6 @@ bool wxScrollBar::IsOwnGtkWindow( GdkWindow *window )
return ( (window == GTK_WIDGET(range)->window) ); return ( (window == GTK_WIDGET(range)->window) );
} }
wxSize wxScrollBar::DoGetBestSize() const
{
return wxControl::DoGetBestSize();
}
// static // static
wxVisualAttributes wxVisualAttributes
wxScrollBar::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) wxScrollBar::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))

View File

@@ -50,8 +50,10 @@ void wxScrollHelperNative::SetScrollbars(int pixelsPerUnitX, int pixelsPerUnitY,
m_xScrollPixelsPerLine = pixelsPerUnitX; m_xScrollPixelsPerLine = pixelsPerUnitX;
m_yScrollPixelsPerLine = pixelsPerUnitY; m_yScrollPixelsPerLine = pixelsPerUnitY;
m_win->m_hAdjust->value = m_xScrollPosition = xPos; m_win->m_scrollBar[0]->adjustment->value =
m_win->m_vAdjust->value = m_yScrollPosition = yPos; m_xScrollPosition = xPos;
m_win->m_scrollBar[1]->adjustment->value =
m_yScrollPosition = yPos;
// Setting hints here should arguably be deprecated, but without it // Setting hints here should arguably be deprecated, but without it
// a sizer might override this manual scrollbar setting in old code. // a sizer might override this manual scrollbar setting in old code.
@@ -62,6 +64,14 @@ void wxScrollHelperNative::SetScrollbars(int pixelsPerUnitX, int pixelsPerUnitY,
m_targetWindow->SetVirtualSize( w ? w : wxDefaultCoord, m_targetWindow->SetVirtualSize( w ? w : wxDefaultCoord,
h ? h : wxDefaultCoord); h ? h : wxDefaultCoord);
// If the target is not the same as the window with the scrollbars,
// then we need to update the scrollbars here, since they won't have
// been updated by SetVirtualSize().
if (m_targetWindow != m_win)
{
AdjustScrollbars();
}
if (!noRefresh) if (!noRefresh)
{ {
int new_x = m_xScrollPixelsPerLine * m_xScrollPosition; int new_x = m_xScrollPixelsPerLine * m_xScrollPosition;
@@ -69,55 +79,33 @@ void wxScrollHelperNative::SetScrollbars(int pixelsPerUnitX, int pixelsPerUnitY,
m_targetWindow->ScrollWindow( old_x - new_x, old_y - new_y ); m_targetWindow->ScrollWindow( old_x - new_x, old_y - new_y );
} }
m_targetWindow->m_hasScrolling = pixelsPerUnitX || pixelsPerUnitY;
} }
void wxScrollHelperNative::DoAdjustScrollbar(GtkAdjustment *adj, void wxScrollHelperNative::DoAdjustScrollbar(GtkRange* range,
int pixelsPerLine, int pixelsPerLine,
int winSize, int winSize,
int virtSize, int virtSize,
int *pos,
int *lines, int *lines,
int *linesPerPage) int *linesPerPage)
{ {
if ( pixelsPerLine == 0 || winSize >= virtSize) // GtkRange won't allow upper == lower, so for disabled state use [0,1]
// with a page size of 1. This will also clamp position to 0.
int upper = 1;
int page_size = 1;
if (pixelsPerLine > 0 && winSize < virtSize)
{ {
if ( !wxIsNullDouble(adj->value) ) upper = (virtSize + pixelsPerLine - 1) / pixelsPerLine;
{ page_size = winSize / pixelsPerLine;
adj->value = 0.0;
g_signal_emit_by_name (adj, "value_changed");
}
adj->upper = 1.0;
adj->page_increment = 1.0;
adj->page_size = 1.0;
}
else // we do have scrollbar
{
// round because we need to show all the items
adj->upper = (virtSize + pixelsPerLine - 1) / pixelsPerLine;
// truncate here as we want to show visible lines entirely
adj->page_size =
adj->page_increment = winSize / pixelsPerLine;
// If the scrollbar hits the right side, move the window
// right to keep it from over extending.
if ( !wxIsNullDouble(adj->value) &&
(adj->value + adj->page_size > adj->upper) )
{
adj->value = adj->upper - adj->page_size;
if (adj->value < 0.0)
adj->value = 0.0;
g_signal_emit_by_name (adj, "value_changed");
}
} }
*lines = (int)(adj->upper + 0.5); *lines = upper;
*linesPerPage = (int)(adj->page_increment + 0.5); *linesPerPage = page_size;
g_signal_emit_by_name (adj, "changed");
GtkAdjustment* adj = range->adjustment;
adj->step_increment = 1;
adj->page_increment =
adj->page_size = page_size;
gtk_range_set_range(range, 0, upper);
} }
void wxScrollHelperNative::AdjustScrollbars() void wxScrollHelperNative::AdjustScrollbars()
@@ -130,37 +118,27 @@ void wxScrollHelperNative::AdjustScrollbars()
m_targetWindow->GetClientSize( &w, &h ); m_targetWindow->GetClientSize( &w, &h );
m_targetWindow->GetVirtualSize( &vw, &vh ); m_targetWindow->GetVirtualSize( &vw, &vh );
DoAdjustScrollbar(m_win->m_hAdjust, m_xScrollPixelsPerLine, w, vw, DoAdjustScrollbar(m_win->m_scrollBar[0], m_xScrollPixelsPerLine, w, vw,
&m_xScrollPosition, &m_xScrollLines, &m_xScrollLinesPerPage); &m_xScrollLines, &m_xScrollLinesPerPage);
DoAdjustScrollbar(m_win->m_vAdjust, m_yScrollPixelsPerLine, h, vh, DoAdjustScrollbar(m_win->m_scrollBar[1], m_yScrollPixelsPerLine, h, vh,
&m_yScrollPosition, &m_yScrollLines, &m_yScrollLinesPerPage); &m_yScrollLines, &m_yScrollLinesPerPage);
} }
void wxScrollHelperNative::DoScroll(int orient, void wxScrollHelperNative::DoScroll(int orient,
GtkAdjustment *adj,
int pos, int pos,
int pixelsPerLine, int pixelsPerLine,
int *posOld) int *posOld)
{ {
if ( pos != -1 && pos != *posOld && pixelsPerLine ) if ( pos != -1 && pos != *posOld && pixelsPerLine )
{ {
int max = (int)(adj->upper - adj->page_size + 0.5); m_win->SetScrollPos(orient, pos);
if (max < 0) pos = m_win->GetScrollPos(orient);
max = 0;
if (pos > max)
pos = max;
if (pos < 0)
pos = 0;
adj->value = pos;
int diff = (*posOld - pos)*pixelsPerLine; int diff = (*posOld - pos)*pixelsPerLine;
m_targetWindow->ScrollWindow(orient == wxHORIZONTAL ? diff : 0, m_targetWindow->ScrollWindow(orient == wxHORIZONTAL ? diff : 0,
orient == wxHORIZONTAL ? 0 : diff); orient == wxHORIZONTAL ? 0 : diff);
*posOld = pos; *posOld = pos;
m_win->GtkUpdateScrollbar(orient);
} }
} }
@@ -168,9 +146,6 @@ void wxScrollHelperNative::Scroll( int x_pos, int y_pos )
{ {
wxCHECK_RET( m_targetWindow != 0, _T("No target window") ); wxCHECK_RET( m_targetWindow != 0, _T("No target window") );
DoScroll(wxHORIZONTAL, m_win->m_hAdjust, x_pos, m_xScrollPixelsPerLine, DoScroll(wxHORIZONTAL, x_pos, m_xScrollPixelsPerLine, &m_xScrollPosition);
&m_xScrollPosition); DoScroll(wxVERTICAL, y_pos, m_yScrollPixelsPerLine, &m_yScrollPosition);
DoScroll(wxVERTICAL, m_win->m_vAdjust, y_pos, m_yScrollPixelsPerLine,
&m_yScrollPosition);
} }

View File

@@ -618,6 +618,8 @@ bool wxTextCtrl::Create( wxWindow *parent,
m_widget = gtk_scrolled_window_new( NULL, NULL ); m_widget = gtk_scrolled_window_new( NULL, NULL );
gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( m_widget ), gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( m_widget ),
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC ); GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC );
// for ScrollLines/Pages
m_scrollBar[1] = (GtkRange*)((GtkScrolledWindow*)m_widget)->vscrollbar;
// Insert view into scrolled window // Insert view into scrolled window
gtk_container_add( GTK_CONTAINER(m_widget), m_text ); gtk_container_add( GTK_CONTAINER(m_widget), m_text );
@@ -670,7 +672,6 @@ bool wxTextCtrl::Create( wxWindow *parent,
if (multi_line) if (multi_line)
{ {
gtk_widget_show(m_text); gtk_widget_show(m_text);
SetVScrollAdjustment(gtk_scrolled_window_get_vadjustment((GtkScrolledWindow*)m_widget));
} }
if (!value.empty()) if (!value.empty())

View File

@@ -2094,65 +2094,23 @@ gtk_window_leave_callback( GtkWidget *widget,
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// "value_changed" from m_vAdjust // "value_changed" from scrollbar
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
extern "C" { extern "C" {
static void gtk_window_vscroll_callback( GtkAdjustment *adjust, static void
wxWindowGTK *win ) gtk_scrollbar_value_changed(GtkRange* range, wxWindow* win)
{ {
DEBUG_MAIN_THREAD wxEventType eventType = win->GetScrollEventType(range);
if (eventType != wxEVT_NULL)
if (g_isIdle) {
wxapp_install_idle_handler(); // Convert scroll event type to scrollwin event type
eventType += wxEVT_SCROLLWIN_TOP - wxEVT_SCROLL_TOP;
if (g_blockEventsOnDrag) return; const int orient = range == win->m_scrollBar[0] ? wxHORIZONTAL : wxVERTICAL;
wxScrollWinEvent event(eventType, win->GetScrollPos(orient), orient);
if (!win->m_hasVMT) return; event.SetEventObject(win);
win->GetEventHandler()->ProcessEvent(event);
float diff = adjust->value - win->m_oldVerticalPos; }
if (fabs(diff) < 0.2) return;
win->m_oldVerticalPos = adjust->value;
wxEventType command = GtkScrollWinTypeToWx(GTK_SCROLL_JUMP);
int value = (int)(adjust->value+0.5);
wxScrollWinEvent event( command, value, wxVERTICAL );
event.SetEventObject( win );
win->GetEventHandler()->ProcessEvent( event );
}
}
//-----------------------------------------------------------------------------
// "value_changed" from m_hAdjust
//-----------------------------------------------------------------------------
extern "C" {
static void gtk_window_hscroll_callback( GtkAdjustment *adjust,
wxWindowGTK *win )
{
DEBUG_MAIN_THREAD
if (g_isIdle)
wxapp_install_idle_handler();
if (g_blockEventsOnDrag) return;
if (!win->m_hasVMT) return;
float diff = adjust->value - win->m_oldHorizontalPos;
if (fabs(diff) < 0.2) return;
wxEventType command = GtkScrollWinTypeToWx(GTK_SCROLL_JUMP);
win->m_oldHorizontalPos = adjust->value;
int value = (int)(adjust->value+0.5);
wxScrollWinEvent event( command, value, wxHORIZONTAL );
event.SetEventObject( win );
win->GetEventHandler()->ProcessEvent( event );
} }
} }
@@ -2162,24 +2120,17 @@ static void gtk_window_hscroll_callback( GtkAdjustment *adjust,
extern "C" { extern "C" {
static gboolean static gboolean
gtk_scrollbar_button_press_callback( GtkWidget *widget, gtk_scrollbar_button_press_event(GtkRange*, GdkEventButton*, wxWindow* win)
GdkEventButton *gdk_event,
wxWindowGTK *win)
{ {
DEBUG_MAIN_THREAD DEBUG_MAIN_THREAD
if (g_isIdle) if (g_isIdle)
wxapp_install_idle_handler(); wxapp_install_idle_handler();
g_blockEventsOnScroll = true; g_blockEventsOnScroll = true;
win->m_mouseButtonDown = true;
// FIXME: there is no 'slider' field in GTK+ 2.0 any more return false;
#if 0
win->m_isScrolling = (gdk_event->window == widget->slider);
#endif
return FALSE;
} }
} }
@@ -2189,45 +2140,23 @@ gtk_scrollbar_button_press_callback( GtkWidget *widget,
extern "C" { extern "C" {
static gboolean static gboolean
gtk_scrollbar_button_release_callback( GtkRange *widget, gtk_scrollbar_button_release_event(GtkRange* range, GdkEventButton*, wxWindow* win)
GdkEventButton *WXUNUSED(gdk_event),
wxWindowGTK *win)
{ {
DEBUG_MAIN_THREAD DEBUG_MAIN_THREAD
// don't test here as we can release the mouse while being over
// a different window than the slider
//
// if (gdk_event->window != widget->slider) return FALSE;
g_blockEventsOnScroll = false; g_blockEventsOnScroll = false;
win->m_mouseButtonDown = false;
// If thumb tracking
if (win->m_isScrolling) if (win->m_isScrolling)
{ {
wxEventType command = wxEVT_SCROLLWIN_THUMBRELEASE; win->m_isScrolling = false;
int value = -1; const int orient = range == win->m_scrollBar[0] ? wxHORIZONTAL : wxVERTICAL;
int dir = -1; wxScrollWinEvent event(wxEVT_SCROLLWIN_THUMBRELEASE, win->GetScrollPos(orient), orient);
event.SetEventObject(win);
GtkScrolledWindow *scrolledWindow = GTK_SCROLLED_WINDOW(win->m_widget); win->GetEventHandler()->ProcessEvent(event);
if (widget == GTK_RANGE(scrolledWindow->hscrollbar))
{
value = (int)(win->m_hAdjust->value+0.5);
dir = wxHORIZONTAL;
}
if (widget == GTK_RANGE(scrolledWindow->vscrollbar))
{
value = (int)(win->m_vAdjust->value+0.5);
dir = wxVERTICAL;
}
wxScrollWinEvent event( command, value, dir );
event.SetEventObject( win );
win->GetEventHandler()->ProcessEvent( event );
} }
win->m_isScrolling = false; return false;
return FALSE;
} }
} }
@@ -2526,11 +2455,14 @@ void wxWindowGTK::Init()
m_hasScrolling = false; m_hasScrolling = false;
m_isScrolling = false; m_isScrolling = false;
m_mouseButtonDown = false;
m_blockScrollEvent = false;
m_scrollBar[0] =
m_scrollBar[1] = NULL;
m_scrollPos[0] =
m_scrollPos[1] = 0;
m_hAdjust = (GtkAdjustment*) NULL;
m_vAdjust = (GtkAdjustment*) NULL;
m_oldHorizontalPos =
m_oldVerticalPos = 0.0;
m_oldClientWidth = m_oldClientWidth =
m_oldClientHeight = 0; m_oldClientHeight = 0;
@@ -2594,8 +2526,8 @@ bool wxWindowGTK::Create( wxWindow *parent,
gtk_scrolled_window_set_policy( scrolledWindow, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC ); gtk_scrolled_window_set_policy( scrolledWindow, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC );
m_hAdjust = gtk_range_get_adjustment( GTK_RANGE(scrolledWindow->hscrollbar) ); m_scrollBar[0] = GTK_RANGE(scrolledWindow->hscrollbar);
m_vAdjust = gtk_range_get_adjustment( GTK_RANGE(scrolledWindow->vscrollbar) ); m_scrollBar[1] = GTK_RANGE(scrolledWindow->vscrollbar);
m_wxwindow = gtk_pizza_new(); m_wxwindow = gtk_pizza_new();
@@ -2625,42 +2557,24 @@ bool wxWindowGTK::Create( wxWindow *parent,
GTK_WIDGET_SET_FLAGS( m_wxwindow, GTK_CAN_FOCUS ); GTK_WIDGET_SET_FLAGS( m_wxwindow, GTK_CAN_FOCUS );
m_acceptsFocus = true; m_acceptsFocus = true;
// I _really_ don't want scrollbars in the beginning
m_vAdjust->lower = 0.0;
m_vAdjust->upper = 1.0;
m_vAdjust->value = 0.0;
m_vAdjust->step_increment = 1.0;
m_vAdjust->page_increment = 1.0;
m_vAdjust->page_size = 5.0;
g_signal_emit_by_name (m_vAdjust, "changed");
m_hAdjust->lower = 0.0;
m_hAdjust->upper = 1.0;
m_hAdjust->value = 0.0;
m_hAdjust->step_increment = 1.0;
m_hAdjust->page_increment = 1.0;
m_hAdjust->page_size = 5.0;
g_signal_emit_by_name (m_hAdjust, "changed");
// these handlers block mouse events to any window during scrolling such as // these handlers block mouse events to any window during scrolling such as
// motion events and prevent GTK and wxWidgets from fighting over where the // motion events and prevent GTK and wxWidgets from fighting over where the
// slider should be // slider should be
g_signal_connect (scrolledWindow->vscrollbar, "button_press_event", g_signal_connect(m_scrollBar[0], "button_press_event",
G_CALLBACK (gtk_scrollbar_button_press_callback), this); G_CALLBACK(gtk_scrollbar_button_press_event), this);
g_signal_connect (scrolledWindow->hscrollbar, "button_press_event", g_signal_connect(m_scrollBar[1], "button_press_event",
G_CALLBACK (gtk_scrollbar_button_press_callback), this); G_CALLBACK(gtk_scrollbar_button_press_event), this);
g_signal_connect (scrolledWindow->vscrollbar, "button_release_event", g_signal_connect(m_scrollBar[0], "button_release_event",
G_CALLBACK (gtk_scrollbar_button_release_callback), this); G_CALLBACK(gtk_scrollbar_button_release_event), this);
g_signal_connect (scrolledWindow->hscrollbar, "button_release_event", g_signal_connect(m_scrollBar[1], "button_release_event",
G_CALLBACK (gtk_scrollbar_button_release_callback), this); G_CALLBACK(gtk_scrollbar_button_release_event), this);
// these handlers get notified when screen updates are required either when // these handlers get notified when scrollbar slider moves
// scrolling or when the window size (and therefore scrollbar configuration)
// has changed
g_signal_connect (m_hAdjust, "value_changed", g_signal_connect(m_scrollBar[0], "value_changed",
G_CALLBACK (gtk_window_hscroll_callback), this); G_CALLBACK(gtk_scrollbar_value_changed), this);
g_signal_connect (m_vAdjust, "value_changed", g_signal_connect(m_scrollBar[1], "value_changed",
G_CALLBACK (gtk_window_vscroll_callback), this); G_CALLBACK(gtk_scrollbar_value_changed), this);
gtk_widget_show( m_wxwindow ); gtk_widget_show( m_wxwindow );
@@ -3676,38 +3590,32 @@ void wxWindowGTK::WarpPointer( int x, int y )
gdk_window_warp_pointer( window, x, 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) bool wxWindowGTK::ScrollLines(int lines)
{ {
return bool changed = false;
m_vAdjust != NULL && GtkRange* range = m_scrollBar[1];
wxScrollAdjust(m_vAdjust, lines * m_vAdjust->step_increment); if (range != NULL)
{
GtkAdjustment* adj = range->adjustment;
const int pos = int(adj->value + 0.5);
gtk_range_set_value(range, pos + lines);
changed = pos != int(adj->value + 0.5);
}
return changed;
} }
bool wxWindowGTK::ScrollPages(int pages) bool wxWindowGTK::ScrollPages(int pages)
{ {
return bool changed = false;
m_vAdjust != NULL && GtkRange* range = m_scrollBar[1];
wxScrollAdjust(m_vAdjust, pages * m_vAdjust->page_increment); if (range != NULL)
} {
GtkAdjustment* adj = range->adjustment;
void wxWindowGTK::SetVScrollAdjustment(GtkAdjustment* adj) const int pos = int(adj->value + 0.5);
{ gtk_range_set_value(range, pos + pages * adj->page_size);
wxASSERT(m_vAdjust == NULL); changed = pos != int(adj->value + 0.5);
m_vAdjust = adj; }
return changed;
} }
void wxWindowGTK::Refresh( bool eraseBackground, const wxRect *rect ) void wxWindowGTK::Refresh( bool eraseBackground, const wxRect *rect )
@@ -4131,80 +4039,38 @@ bool wxWindowGTK::IsRetained() const
return false; return false;
} }
void wxWindowGTK::BlockScrollEvent()
{
wxASSERT(!m_blockScrollEvent);
m_blockScrollEvent = true;
}
void wxWindowGTK::UnblockScrollEvent()
{
wxASSERT(m_blockScrollEvent);
m_blockScrollEvent = false;
}
void wxWindowGTK::SetScrollbar( int orient, int pos, int thumbVisible, void wxWindowGTK::SetScrollbar( int orient, int pos, int thumbVisible,
int range, bool refresh ) int range, bool )
{ {
wxCHECK_RET( m_widget != NULL, wxT("invalid window") ); wxCHECK_RET( m_widget != NULL, wxT("invalid window") );
wxCHECK_RET( m_wxwindow != NULL, wxT("window needs client area for scrolling") ); wxCHECK_RET( m_wxwindow != NULL, wxT("window needs client area for scrolling") );
m_hasScrolling = true; m_hasScrolling = true;
if (orient == wxHORIZONTAL) const int i = orient == wxVERTICAL;
{ GtkAdjustment* adj = m_scrollBar[i]->adjustment;
float fpos = (float)pos; adj->value = pos;
float frange = (float)range; adj->step_increment = 1;
float fthumb = (float)thumbVisible; adj->page_increment =
if (fpos > frange-fthumb) fpos = frange-fthumb; adj->page_size = thumbVisible;
if (fpos < 0.0) fpos = 0.0;
if ((fabs(frange-m_hAdjust->upper) < 0.2) && BlockScrollEvent();
(fabs(fthumb-m_hAdjust->page_size) < 0.2)) // automatically clamps value to [0,range-page_size], and emits change events
{ gtk_range_set_range(m_scrollBar[i], 0, range);
SetScrollPos( orient, pos, refresh ); UnblockScrollEvent();
return; m_scrollPos[i] = adj->value;
}
m_oldHorizontalPos = fpos;
m_hAdjust->lower = 0.0;
m_hAdjust->upper = frange;
m_hAdjust->value = fpos;
m_hAdjust->step_increment = 1.0;
m_hAdjust->page_increment = (float)(wxMax(fthumb,0));
m_hAdjust->page_size = fthumb;
}
else
{
float fpos = (float)pos;
float frange = (float)range;
float fthumb = (float)thumbVisible;
if (fpos > frange-fthumb) fpos = frange-fthumb;
if (fpos < 0.0) fpos = 0.0;
if ((fabs(frange-m_vAdjust->upper) < 0.2) &&
(fabs(fthumb-m_vAdjust->page_size) < 0.2))
{
SetScrollPos( orient, pos, refresh );
return;
}
m_oldVerticalPos = fpos;
m_vAdjust->lower = 0.0;
m_vAdjust->upper = frange;
m_vAdjust->value = fpos;
m_vAdjust->step_increment = 1.0;
m_vAdjust->page_increment = (float)(wxMax(fthumb,0));
m_vAdjust->page_size = fthumb;
}
if (orient == wxHORIZONTAL)
g_signal_emit_by_name (m_hAdjust, "changed");
else
g_signal_emit_by_name (m_vAdjust, "changed");
}
void wxWindowGTK::GtkUpdateScrollbar(int orient)
{
GtkAdjustment *adj = orient == wxHORIZONTAL ? m_hAdjust : m_vAdjust;
gpointer fn = orient == wxHORIZONTAL
? (gpointer) gtk_window_hscroll_callback
: (gpointer) gtk_window_vscroll_callback;
g_signal_handlers_disconnect_by_func (adj, fn, this);
g_signal_emit_by_name (adj, "value_changed");
g_signal_connect (adj, "value_changed", G_CALLBACK (fn), this);
} }
void wxWindowGTK::SetScrollPos( int orient, int pos, bool WXUNUSED(refresh) ) void wxWindowGTK::SetScrollPos( int orient, int pos, bool WXUNUSED(refresh) )
@@ -4212,58 +4078,98 @@ void wxWindowGTK::SetScrollPos( int orient, int pos, bool WXUNUSED(refresh) )
wxCHECK_RET( m_widget != NULL, wxT("invalid window") ); wxCHECK_RET( m_widget != NULL, wxT("invalid window") );
wxCHECK_RET( m_wxwindow != NULL, wxT("window needs client area for scrolling") ); wxCHECK_RET( m_wxwindow != NULL, wxT("window needs client area for scrolling") );
GtkAdjustment *adj = orient == wxHORIZONTAL ? m_hAdjust : m_vAdjust; // This check is more than an optimization. Without it, the slider
// will not move smoothly while tracking when using wxScrollHelper.
float fpos = (float)pos; if (GetScrollPos(orient) != pos)
if (fpos > adj->upper - adj->page_size)
fpos = adj->upper - adj->page_size;
if (fpos < 0.0)
fpos = 0.0;
*(orient == wxHORIZONTAL ? &m_oldHorizontalPos : &m_oldVerticalPos) = fpos;
if (fabs(fpos-adj->value) < 0.2)
return;
adj->value = fpos;
if ( m_wxwindow->window )
{ {
const int i = orient == wxVERTICAL;
BlockScrollEvent();
gtk_range_set_value(m_scrollBar[i], pos);
UnblockScrollEvent();
m_scrollPos[i] = m_scrollBar[i]->adjustment->value;
} }
} }
int wxWindowGTK::GetScrollThumb( int orient ) const int wxWindowGTK::GetScrollThumb( int orient ) const
{ {
wxCHECK_MSG( m_widget != NULL, 0, wxT("invalid window") ); wxCHECK_MSG( m_widget != NULL, 0, wxT("invalid window") );
wxCHECK_MSG( m_wxwindow != NULL, 0, wxT("window needs client area for scrolling") ); wxCHECK_MSG( m_wxwindow != NULL, 0, wxT("window needs client area for scrolling") );
if (orient == wxHORIZONTAL) const int i = orient == wxVERTICAL;
return (int)(m_hAdjust->page_size+0.5); return int(m_scrollBar[i]->adjustment->page_size);
else
return (int)(m_vAdjust->page_size+0.5);
} }
int wxWindowGTK::GetScrollPos( int orient ) const int wxWindowGTK::GetScrollPos( int orient ) const
{ {
wxCHECK_MSG( m_widget != NULL, 0, wxT("invalid window") ); wxCHECK_MSG( m_widget != NULL, 0, wxT("invalid window") );
wxCHECK_MSG( m_wxwindow != NULL, 0, wxT("window needs client area for scrolling") ); wxCHECK_MSG( m_wxwindow != NULL, 0, wxT("window needs client area for scrolling") );
if (orient == wxHORIZONTAL) const int i = orient == wxVERTICAL;
return (int)(m_hAdjust->value+0.5); return int(m_scrollBar[i]->adjustment->value + 0.5);
else
return (int)(m_vAdjust->value+0.5);
} }
int wxWindowGTK::GetScrollRange( int orient ) const int wxWindowGTK::GetScrollRange( int orient ) const
{ {
wxCHECK_MSG( m_widget != NULL, 0, wxT("invalid window") ); wxCHECK_MSG( m_widget != NULL, 0, wxT("invalid window") );
wxCHECK_MSG( m_wxwindow != NULL, 0, wxT("window needs client area for scrolling") ); wxCHECK_MSG( m_wxwindow != NULL, 0, wxT("window needs client area for scrolling") );
if (orient == wxHORIZONTAL) const int i = orient == wxVERTICAL;
return (int)(m_hAdjust->upper+0.5); return int(m_scrollBar[i]->adjustment->upper);
else }
return (int)(m_vAdjust->upper+0.5);
// Determine if increment is the same as +/-x, allowing for some small
// difference due to possible inexactness in floating point arithmetic
static inline bool IsScrollIncrement(double increment, double x)
{
wxASSERT(increment > 0);
const double tolerance = 1.0 / 1024;
return fabs(increment - fabs(x)) < tolerance;
}
wxEventType wxWindow::GetScrollEventType(GtkRange* range)
{
DEBUG_MAIN_THREAD
if (g_isIdle)
wxapp_install_idle_handler();
wxASSERT(range == m_scrollBar[0] || range == m_scrollBar[1]);
const int barIndex = range == m_scrollBar[1];
GtkAdjustment* adj = range->adjustment;
const int value = int(adj->value + 0.5);
// save previous position
const double oldPos = m_scrollPos[barIndex];
// update current position
m_scrollPos[barIndex] = adj->value;
// If event should be ignored, or integral position has not changed
if (!m_hasVMT || g_blockEventsOnDrag || m_blockScrollEvent || value == int(oldPos + 0.5))
{
return wxEVT_NULL;
}
wxEventType eventType = wxEVT_SCROLL_THUMBTRACK;
if (!m_isScrolling)
{
// Difference from last change event
const double diff = adj->value - oldPos;
const bool isDown = diff > 0;
if (IsScrollIncrement(adj->step_increment, diff))
{
eventType = isDown ? wxEVT_SCROLL_LINEDOWN : wxEVT_SCROLL_LINEUP;
}
else if (IsScrollIncrement(adj->page_increment, diff))
{
eventType = isDown ? wxEVT_SCROLL_PAGEDOWN : wxEVT_SCROLL_PAGEUP;
}
else if (m_mouseButtonDown)
{
// Assume track event
m_isScrolling = true;
}
}
return eventType;
} }
void wxWindowGTK::ScrollWindow( int dx, int dy, const wxRect* WXUNUSED(rect) ) void wxWindowGTK::ScrollWindow( int dx, int dy, const wxRect* WXUNUSED(rect) )