1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/scrolbar.cpp
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
15 #include "wx/scrolbar.h"
21 #include "wx/gtk/private.h"
23 //-----------------------------------------------------------------------------
24 // "value_changed" from scrollbar
25 //-----------------------------------------------------------------------------
29 gtk_value_changed(GtkRange
* range
, wxScrollBar
* win
)
31 wxEventType eventType
= win
->GetScrollEventType(range
);
32 if (eventType
!= wxEVT_NULL
)
34 const int orient
= win
->HasFlag(wxSB_VERTICAL
) ? wxVERTICAL
: wxHORIZONTAL
;
35 const int value
= win
->GetThumbPosition();
36 wxScrollEvent
event(eventType
, win
->GetId(), value
, orient
);
37 event
.SetEventObject(win
);
38 win
->GetEventHandler()->ProcessEvent(event
);
39 if (!win
->m_isScrolling
)
41 wxScrollEvent
event(wxEVT_SCROLL_CHANGED
, win
->GetId(), value
, orient
);
42 event
.SetEventObject(win
);
43 win
->GetEventHandler()->ProcessEvent(event
);
49 //-----------------------------------------------------------------------------
50 // "button_press_event" from scrollbar
51 //-----------------------------------------------------------------------------
55 gtk_button_press_event(GtkRange
*, GdkEventButton
*, wxScrollBar
* win
)
57 if (g_isIdle
) wxapp_install_idle_handler();
59 win
->m_mouseButtonDown
= true;
64 //-----------------------------------------------------------------------------
65 // "button_release_event" from scrollbar
66 //-----------------------------------------------------------------------------
70 gtk_button_release_event(GtkRange
*, GdkEventButton
*, wxScrollBar
* win
)
73 wxapp_install_idle_handler();
75 win
->m_mouseButtonDown
= false;
77 if (win
->m_isScrolling
)
79 win
->m_isScrolling
= false;
80 const int value
= win
->GetThumbPosition();
81 const int orient
= win
->HasFlag(wxSB_VERTICAL
) ? wxVERTICAL
: wxHORIZONTAL
;
83 wxScrollEvent
event(wxEVT_SCROLL_THUMBRELEASE
, win
->GetId(), value
, orient
);
84 event
.SetEventObject(win
);
85 win
->GetEventHandler()->ProcessEvent(event
);
87 wxScrollEvent
event2(wxEVT_SCROLL_CHANGED
, win
->GetId(), value
, orient
);
88 event2
.SetEventObject(win
);
89 win
->GetEventHandler()->ProcessEvent(event2
);
96 //-----------------------------------------------------------------------------
98 //-----------------------------------------------------------------------------
100 IMPLEMENT_DYNAMIC_CLASS(wxScrollBar
,wxControl
)
102 wxScrollBar::wxScrollBar()
106 wxScrollBar::~wxScrollBar()
110 bool wxScrollBar::Create(wxWindow
*parent
, wxWindowID id
,
111 const wxPoint
& pos
, const wxSize
& size
,
112 long style
, const wxValidator
& validator
, const wxString
& name
)
115 m_acceptsFocus
= true;
117 if (!PreCreation( parent
, pos
, size
) ||
118 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
120 wxFAIL_MSG( wxT("wxScrollBar creation failed") );
124 const bool isVertical
= (style
& wxSB_VERTICAL
) != 0;
126 m_widget
= gtk_vscrollbar_new( (GtkAdjustment
*) NULL
);
128 m_widget
= gtk_hscrollbar_new( (GtkAdjustment
*) NULL
);
130 m_scrollBar
[int(isVertical
)] = (GtkRange
*)m_widget
;
132 g_signal_connect(m_widget
, "value_changed",
133 G_CALLBACK(gtk_value_changed
), this);
134 g_signal_connect(m_widget
, "button_press_event",
135 G_CALLBACK(gtk_button_press_event
), this);
136 g_signal_connect(m_widget
, "button_release_event",
137 G_CALLBACK(gtk_button_release_event
), this);
139 m_parent
->DoAddChild( this );
146 int wxScrollBar::GetThumbPosition() const
148 GtkAdjustment
* adj
= ((GtkRange
*)m_widget
)->adjustment
;
149 return int(adj
->value
+ 0.5);
152 int wxScrollBar::GetThumbSize() const
154 GtkAdjustment
* adj
= ((GtkRange
*)m_widget
)->adjustment
;
155 return int(adj
->page_size
);
158 int wxScrollBar::GetPageSize() const
160 GtkAdjustment
* adj
= ((GtkRange
*)m_widget
)->adjustment
;
161 return int(adj
->page_increment
);
164 int wxScrollBar::GetRange() const
166 GtkAdjustment
* adj
= ((GtkRange
*)m_widget
)->adjustment
;
167 return int(adj
->upper
);
170 void wxScrollBar::SetThumbPosition( int viewStart
)
172 if (GetThumbPosition() != viewStart
)
175 gtk_range_set_value((GtkRange
*)m_widget
, viewStart
);
176 UnblockScrollEvent();
177 GtkAdjustment
* adj
= ((GtkRange
*)m_widget
)->adjustment
;
178 const int i
= HasFlag(wxSB_VERTICAL
);
179 m_scrollPos
[i
] = adj
->value
;
183 void wxScrollBar::SetScrollbar(int position
, int thumbSize
, int range
, int pageSize
, bool)
185 GtkAdjustment
* adj
= ((GtkRange
*)m_widget
)->adjustment
;
186 adj
->value
= position
;
187 adj
->step_increment
= 1;
188 adj
->page_increment
= pageSize
;
189 adj
->page_size
= thumbSize
;
191 gtk_range_set_range((GtkRange
*)m_widget
, 0, range
);
192 UnblockScrollEvent();
193 const int i
= HasFlag(wxSB_VERTICAL
);
194 m_scrollPos
[i
] = adj
->value
;
197 void wxScrollBar::SetPageSize( int pageLength
)
199 SetScrollbar(GetThumbPosition(), GetThumbSize(), GetRange(), pageLength
);
202 void wxScrollBar::SetRange(int range
)
204 SetScrollbar(GetThumbPosition(), GetThumbSize(), range
, GetPageSize());
207 bool wxScrollBar::IsOwnGtkWindow( GdkWindow
*window
)
209 GtkRange
*range
= GTK_RANGE(m_widget
);
210 return ( (window
== GTK_WIDGET(range
)->window
) );
215 wxScrollBar::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
217 return GetDefaultAttributesFromGTKWidget(gtk_vscrollbar_new
);
220 #endif // wxUSE_SCROLLBAR