]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/gtk/scrolbar.cpp
fix for HP and IBM compilers, calls to static template functions must be qualified
[wxWidgets.git] / src / gtk / scrolbar.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/gtk/scrolbar.cpp
3// Purpose:
4// Author: Robert Roebling
5// Id: $Id$
6// Copyright: (c) 1998 Robert Roebling
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
9
10// For compilers that support precompilation, includes "wx.h".
11#include "wx/wxprec.h"
12
13#if wxUSE_SCROLLBAR
14
15#include "wx/scrolbar.h"
16
17#ifndef WX_PRECOMP
18 #include "wx/utils.h"
19#endif
20
21#include "wx/gtk/private.h"
22
23//-----------------------------------------------------------------------------
24// "value_changed" from scrollbar
25//-----------------------------------------------------------------------------
26
27extern "C" {
28static void
29gtk_value_changed(GtkRange* range, wxScrollBar* win)
30{
31 wxEventType eventType = win->GetScrollEventType(range);
32 if (eventType != wxEVT_NULL)
33 {
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)
40 {
41 wxScrollEvent event(wxEVT_SCROLL_CHANGED, win->GetId(), value, orient);
42 event.SetEventObject(win);
43 win->GetEventHandler()->ProcessEvent(event);
44 }
45 }
46}
47}
48
49//-----------------------------------------------------------------------------
50// "button_press_event" from scrollbar
51//-----------------------------------------------------------------------------
52
53extern "C" {
54static gboolean
55gtk_button_press_event(GtkRange*, GdkEventButton*, wxScrollBar* win)
56{
57 win->m_mouseButtonDown = true;
58 return false;
59}
60}
61
62//-----------------------------------------------------------------------------
63// "event_after" from scrollbar
64//-----------------------------------------------------------------------------
65
66extern "C" {
67static void
68gtk_event_after(GtkRange* range, GdkEvent* event, wxScrollBar* win)
69{
70 if (event->type == GDK_BUTTON_RELEASE)
71 {
72 g_signal_handlers_block_by_func(range, (void*)gtk_event_after, win);
73
74 const int value = win->GetThumbPosition();
75 const int orient = win->HasFlag(wxSB_VERTICAL) ? wxVERTICAL : wxHORIZONTAL;
76
77 wxScrollEvent event(wxEVT_SCROLL_THUMBRELEASE, win->GetId(), value, orient);
78 event.SetEventObject(win);
79 win->GetEventHandler()->ProcessEvent(event);
80
81 wxScrollEvent event2(wxEVT_SCROLL_CHANGED, win->GetId(), value, orient);
82 event2.SetEventObject(win);
83 win->GetEventHandler()->ProcessEvent(event2);
84 }
85}
86}
87
88//-----------------------------------------------------------------------------
89// "button_release_event" from scrollbar
90//-----------------------------------------------------------------------------
91
92extern "C" {
93static gboolean
94gtk_button_release_event(GtkRange* range, GdkEventButton*, wxScrollBar* win)
95{
96 win->m_mouseButtonDown = false;
97 // If thumb tracking
98 if (win->m_isScrolling)
99 {
100 win->m_isScrolling = false;
101 // Hook up handler to send thumb release event after this emission is finished.
102 // To allow setting scroll position from event handler, sending event must
103 // be deferred until after the GtkRange handler for this signal has run
104 g_signal_handlers_unblock_by_func(range, (void*)gtk_event_after, win);
105 }
106
107 return false;
108}
109}
110
111//-----------------------------------------------------------------------------
112// wxScrollBar
113//-----------------------------------------------------------------------------
114
115IMPLEMENT_DYNAMIC_CLASS(wxScrollBar,wxControl)
116
117wxScrollBar::wxScrollBar()
118{
119}
120
121wxScrollBar::~wxScrollBar()
122{
123}
124
125bool wxScrollBar::Create(wxWindow *parent, wxWindowID id,
126 const wxPoint& pos, const wxSize& size,
127 long style, const wxValidator& validator, const wxString& name )
128{
129 if (!PreCreation( parent, pos, size ) ||
130 !CreateBase( parent, id, pos, size, style, validator, name ))
131 {
132 wxFAIL_MSG( wxT("wxScrollBar creation failed") );
133 return false;
134 }
135
136 const bool isVertical = (style & wxSB_VERTICAL) != 0;
137 if (isVertical)
138 m_widget = gtk_vscrollbar_new( (GtkAdjustment *) NULL );
139 else
140 m_widget = gtk_hscrollbar_new( (GtkAdjustment *) NULL );
141
142 m_scrollBar[0] = (GtkRange*)m_widget;
143
144 g_signal_connect_after(m_widget, "value_changed",
145 G_CALLBACK(gtk_value_changed), this);
146 g_signal_connect(m_widget, "button_press_event",
147 G_CALLBACK(gtk_button_press_event), this);
148 g_signal_connect(m_widget, "button_release_event",
149 G_CALLBACK(gtk_button_release_event), this);
150
151 gulong handler_id;
152 handler_id = g_signal_connect(
153 m_widget, "event_after", G_CALLBACK(gtk_event_after), this);
154 g_signal_handler_block(m_widget, handler_id);
155
156 m_parent->DoAddChild( this );
157
158 PostCreation(size);
159
160 return true;
161}
162
163int wxScrollBar::GetThumbPosition() const
164{
165 GtkAdjustment* adj = ((GtkRange*)m_widget)->adjustment;
166 return int(adj->value + 0.5);
167}
168
169int wxScrollBar::GetThumbSize() const
170{
171 GtkAdjustment* adj = ((GtkRange*)m_widget)->adjustment;
172 return int(adj->page_size);
173}
174
175int wxScrollBar::GetPageSize() const
176{
177 GtkAdjustment* adj = ((GtkRange*)m_widget)->adjustment;
178 return int(adj->page_increment);
179}
180
181int wxScrollBar::GetRange() const
182{
183 GtkAdjustment* adj = ((GtkRange*)m_widget)->adjustment;
184 return int(adj->upper);
185}
186
187void wxScrollBar::SetThumbPosition( int viewStart )
188{
189 if (GetThumbPosition() != viewStart)
190 {
191 g_signal_handlers_block_by_func(m_widget,
192 (gpointer)gtk_value_changed, this);
193
194 gtk_range_set_value((GtkRange*)m_widget, viewStart);
195 m_scrollPos[0] = gtk_range_get_value((GtkRange*)m_widget);
196
197 g_signal_handlers_unblock_by_func(m_widget,
198 (gpointer)gtk_value_changed, this);
199 }
200}
201
202void wxScrollBar::SetScrollbar(int position, int thumbSize, int range, int pageSize, bool)
203{
204 if (range == 0)
205 {
206 // GtkRange requires upper > lower
207 range =
208 thumbSize = 1;
209 }
210 GtkAdjustment* adj = ((GtkRange*)m_widget)->adjustment;
211 adj->step_increment = 1;
212 adj->page_increment = pageSize;
213 adj->page_size = thumbSize;
214 adj->value = position;
215 g_signal_handlers_block_by_func(m_widget, (void*)gtk_value_changed, this);
216 gtk_range_set_range((GtkRange*)m_widget, 0, range);
217 m_scrollPos[0] = adj->value;
218 g_signal_handlers_unblock_by_func(m_widget, (void*)gtk_value_changed, this);
219}
220
221void wxScrollBar::SetPageSize( int pageLength )
222{
223 SetScrollbar(GetThumbPosition(), GetThumbSize(), GetRange(), pageLength);
224}
225
226void wxScrollBar::SetRange(int range)
227{
228 SetScrollbar(GetThumbPosition(), GetThumbSize(), range, GetPageSize());
229}
230
231GdkWindow *wxScrollBar::GTKGetWindow(wxArrayGdkWindows& WXUNUSED(windows)) const
232{
233 return m_widget->window;
234}
235
236// static
237wxVisualAttributes
238wxScrollBar::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
239{
240 return GetDefaultAttributesFromGTKWidget(gtk_vscrollbar_new);
241}
242
243#endif // wxUSE_SCROLLBAR