]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/scrolbar.cpp
Fix stc doxygen warnings and regen stc files.
[wxWidgets.git] / src / gtk / scrolbar.cpp
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
1e6feb95 2// Name: src/gtk/scrolbar.cpp
c801d85f
KB
3// Purpose:
4// Author: Robert Roebling
f96aa4d9 5// Copyright: (c) 1998 Robert Roebling
65571936 6// Licence: wxWindows licence
c801d85f
KB
7/////////////////////////////////////////////////////////////////////////////
8
14f355c2
VS
9// For compilers that support precompilation, includes "wx.h".
10#include "wx/wxprec.h"
dcf924a3
RR
11
12#if wxUSE_SCROLLBAR
13
1e6feb95
VZ
14#include "wx/scrolbar.h"
15
de6185e2
WS
16#ifndef WX_PRECOMP
17 #include "wx/utils.h"
18#endif
19
9e691f46 20#include "wx/gtk/private.h"
83624f79 21
66bd6b93 22//-----------------------------------------------------------------------------
add7cadd 23// "value_changed" from scrollbar
66bd6b93
RR
24//-----------------------------------------------------------------------------
25
865bb325 26extern "C" {
add7cadd
PC
27static void
28gtk_value_changed(GtkRange* range, wxScrollBar* win)
a2615ebc 29{
71ead4bf 30 wxEventType eventType = win->GTKGetScrollEventType(range);
add7cadd 31 if (eventType != wxEVT_NULL)
7c2f14ee 32 {
add7cadd
PC
33 const int orient = win->HasFlag(wxSB_VERTICAL) ? wxVERTICAL : wxHORIZONTAL;
34 const int value = win->GetThumbPosition();
74ab5f5b
VZ
35 const int id = win->GetId();
36
37 // first send the specific event for the user action
38 wxScrollEvent evtSpec(eventType, id, value, orient);
39 evtSpec.SetEventObject(win);
937013e0 40 win->HandleWindowEvent(evtSpec);
74ab5f5b 41
add7cadd
PC
42 if (!win->m_isScrolling)
43 {
74ab5f5b
VZ
44 // and if it's over also send a general "changed" event
45 wxScrollEvent evtChanged(wxEVT_SCROLL_CHANGED, id, value, orient);
46 evtChanged.SetEventObject(win);
937013e0 47 win->HandleWindowEvent(evtChanged);
add7cadd 48 }
91af0895 49 }
6de97a3b 50}
865bb325 51}
c801d85f 52
cb43b372 53//-----------------------------------------------------------------------------
add7cadd 54// "button_press_event" from scrollbar
cb43b372 55//-----------------------------------------------------------------------------
add7cadd 56
865bb325 57extern "C" {
add7cadd
PC
58static gboolean
59gtk_button_press_event(GtkRange*, GdkEventButton*, wxScrollBar* win)
cb43b372 60{
add7cadd
PC
61 win->m_mouseButtonDown = true;
62 return false;
cb43b372 63}
865bb325 64}
cb43b372 65
c918b2cd
PC
66//-----------------------------------------------------------------------------
67// "event_after" from scrollbar
68//-----------------------------------------------------------------------------
69
70extern "C" {
71static void
72gtk_event_after(GtkRange* range, GdkEvent* event, wxScrollBar* win)
73{
74 if (event->type == GDK_BUTTON_RELEASE)
75 {
76 g_signal_handlers_block_by_func(range, (void*)gtk_event_after, win);
77
78 const int value = win->GetThumbPosition();
79 const int orient = win->HasFlag(wxSB_VERTICAL) ? wxVERTICAL : wxHORIZONTAL;
74ab5f5b 80 const int id = win->GetId();
c918b2cd 81
74ab5f5b
VZ
82 wxScrollEvent evtRel(wxEVT_SCROLL_THUMBRELEASE, id, value, orient);
83 evtRel.SetEventObject(win);
937013e0 84 win->HandleWindowEvent(evtRel);
c918b2cd 85
74ab5f5b
VZ
86 wxScrollEvent evtChanged(wxEVT_SCROLL_CHANGED, id, value, orient);
87 evtChanged.SetEventObject(win);
937013e0 88 win->HandleWindowEvent(evtChanged);
c918b2cd
PC
89 }
90}
91}
92
cb43b372 93//-----------------------------------------------------------------------------
add7cadd 94// "button_release_event" from scrollbar
cb43b372
RR
95//-----------------------------------------------------------------------------
96
865bb325 97extern "C" {
add7cadd 98static gboolean
c918b2cd 99gtk_button_release_event(GtkRange* range, GdkEventButton*, wxScrollBar* win)
cb43b372 100{
add7cadd
PC
101 win->m_mouseButtonDown = false;
102 // If thumb tracking
2a23d363
RR
103 if (win->m_isScrolling)
104 {
add7cadd 105 win->m_isScrolling = false;
c918b2cd 106 // Hook up handler to send thumb release event after this emission is finished.
8ea30e36
PC
107 // To allow setting scroll position from event handler, sending event must
108 // be deferred until after the GtkRange handler for this signal has run
c918b2cd 109 g_signal_handlers_unblock_by_func(range, (void*)gtk_event_after, win);
add7cadd 110 }
7c2f14ee 111
add7cadd 112 return false;
cb43b372 113}
865bb325 114}
cb43b372 115
b4071e91
RR
116//-----------------------------------------------------------------------------
117// wxScrollBar
118//-----------------------------------------------------------------------------
119
add7cadd
PC
120wxScrollBar::wxScrollBar()
121{
122}
123
0a07a7d8 124wxScrollBar::~wxScrollBar()
c801d85f 125{
6de97a3b 126}
c801d85f 127
debe6624 128bool wxScrollBar::Create(wxWindow *parent, wxWindowID id,
c801d85f 129 const wxPoint& pos, const wxSize& size,
6de97a3b 130 long style, const wxValidator& validator, const wxString& name )
c801d85f 131{
4dcaf11a
RR
132 if (!PreCreation( parent, pos, size ) ||
133 !CreateBase( parent, id, pos, size, style, validator, name ))
134 {
223d09f6 135 wxFAIL_MSG( wxT("wxScrollBar creation failed") );
91af0895 136 return false;
4dcaf11a 137 }
6de97a3b 138
add7cadd 139 const bool isVertical = (style & wxSB_VERTICAL) != 0;
1897abe1 140 m_widget = gtk_scrollbar_new(GtkOrientation(isVertical), NULL);
9ff9d30c 141 g_object_ref(m_widget);
d9bd1494 142
63c95f27 143 m_scrollBar[0] = (GtkRange*)m_widget;
a2615ebc 144
40e5ebbf 145 g_signal_connect_after(m_widget, "value_changed",
add7cadd
PC
146 G_CALLBACK(gtk_value_changed), this);
147 g_signal_connect(m_widget, "button_press_event",
148 G_CALLBACK(gtk_button_press_event), this);
149 g_signal_connect(m_widget, "button_release_event",
150 G_CALLBACK(gtk_button_release_event), this);
cb43b372 151
c918b2cd
PC
152 gulong handler_id;
153 handler_id = g_signal_connect(
154 m_widget, "event_after", G_CALLBACK(gtk_event_after), this);
155 g_signal_handler_block(m_widget, handler_id);
156
f03fc89f 157 m_parent->DoAddChild( this );
a2615ebc 158
abdeb9e7 159 PostCreation(size);
a2615ebc 160
91af0895 161 return true;
6de97a3b 162}
c801d85f 163
0a07a7d8 164int wxScrollBar::GetThumbPosition() const
c801d85f 165{
385e8575 166 return wxRound(gtk_range_get_value(GTK_RANGE(m_widget)));
6de97a3b 167}
c801d85f
KB
168
169int wxScrollBar::GetThumbSize() const
170{
385e8575
PC
171 GtkAdjustment* adj = gtk_range_get_adjustment(GTK_RANGE(m_widget));
172 return int(gtk_adjustment_get_page_size(adj));
6de97a3b 173}
c801d85f
KB
174
175int wxScrollBar::GetPageSize() const
176{
385e8575
PC
177 GtkAdjustment* adj = gtk_range_get_adjustment(GTK_RANGE(m_widget));
178 return int(gtk_adjustment_get_page_increment(adj));
6de97a3b 179}
c801d85f
KB
180
181int wxScrollBar::GetRange() const
182{
385e8575
PC
183 GtkAdjustment* adj = gtk_range_get_adjustment(GTK_RANGE(m_widget));
184 return int(gtk_adjustment_get_upper(adj));
6de97a3b 185}
c801d85f 186
4fabb575 187void wxScrollBar::SetThumbPosition( int viewStart )
c801d85f 188{
add7cadd 189 if (GetThumbPosition() != viewStart)
2d17d68f 190 {
98264520
PC
191 g_signal_handlers_block_by_func(m_widget,
192 (gpointer)gtk_value_changed, this);
40e5ebbf 193
63c95f27
PC
194 gtk_range_set_value((GtkRange*)m_widget, viewStart);
195 m_scrollPos[0] = gtk_range_get_value((GtkRange*)m_widget);
98264520
PC
196
197 g_signal_handlers_unblock_by_func(m_widget,
198 (gpointer)gtk_value_changed, this);
2d17d68f 199 }
6de97a3b 200}
c801d85f 201
add7cadd 202void wxScrollBar::SetScrollbar(int position, int thumbSize, int range, int pageSize, bool)
c801d85f 203{
de7bb802
PC
204 if (range == 0)
205 {
206 // GtkRange requires upper > lower
207 range =
208 thumbSize = 1;
209 }
63c95f27 210 g_signal_handlers_block_by_func(m_widget, (void*)gtk_value_changed, this);
385e8575
PC
211 GtkRange* widget = GTK_RANGE(m_widget);
212 gtk_adjustment_set_page_size(gtk_range_get_adjustment(widget), thumbSize);
213 gtk_range_set_increments(widget, 1, pageSize);
214 gtk_range_set_range(widget, 0, range);
215 gtk_range_set_value(widget, position);
216 m_scrollPos[0] = gtk_range_get_value(widget);
63c95f27 217 g_signal_handlers_unblock_by_func(m_widget, (void*)gtk_value_changed, this);
6de97a3b 218}
c801d85f 219
debe6624 220void wxScrollBar::SetPageSize( int pageLength )
c801d85f 221{
add7cadd 222 SetScrollbar(GetThumbPosition(), GetThumbSize(), GetRange(), pageLength);
6de97a3b 223}
c801d85f 224
add7cadd 225void wxScrollBar::SetRange(int range)
c801d85f 226{
add7cadd 227 SetScrollbar(GetThumbPosition(), GetThumbSize(), range, GetPageSize());
6de97a3b 228}
c801d85f 229
9d522606
RD
230// static
231wxVisualAttributes
232wxScrollBar::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
233{
1897abe1 234 return GetDefaultAttributesFromGTKWidget(gtk_scrollbar_new(GTK_ORIENTATION_VERTICAL, NULL));
9d522606
RD
235}
236
de6185e2 237#endif // wxUSE_SCROLLBAR