]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/scrolbar.cpp
Combobox may not be fully created at this point
[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
RR
5// Id: $Id$
6// Copyright: (c) 1998 Robert Roebling
65571936 7// Licence: wxWindows licence
c801d85f
KB
8/////////////////////////////////////////////////////////////////////////////
9
14f355c2
VS
10// For compilers that support precompilation, includes "wx.h".
11#include "wx/wxprec.h"
dcf924a3
RR
12
13#if wxUSE_SCROLLBAR
14
1e6feb95
VZ
15#include "wx/scrolbar.h"
16
de6185e2
WS
17#ifndef WX_PRECOMP
18 #include "wx/utils.h"
19#endif
20
9e691f46 21#include "wx/gtk/private.h"
83624f79 22
66bd6b93 23//-----------------------------------------------------------------------------
add7cadd 24// "value_changed" from scrollbar
66bd6b93
RR
25//-----------------------------------------------------------------------------
26
865bb325 27extern "C" {
add7cadd
PC
28static void
29gtk_value_changed(GtkRange* range, wxScrollBar* win)
a2615ebc 30{
add7cadd
PC
31 wxEventType eventType = win->GetScrollEventType(range);
32 if (eventType != wxEVT_NULL)
7c2f14ee 33 {
add7cadd
PC
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 }
91af0895 45 }
6de97a3b 46}
865bb325 47}
c801d85f 48
cb43b372 49//-----------------------------------------------------------------------------
add7cadd 50// "button_press_event" from scrollbar
cb43b372 51//-----------------------------------------------------------------------------
add7cadd 52
865bb325 53extern "C" {
add7cadd
PC
54static gboolean
55gtk_button_press_event(GtkRange*, GdkEventButton*, wxScrollBar* win)
cb43b372 56{
acfd422a
RR
57 if (g_isIdle) wxapp_install_idle_handler();
58
add7cadd
PC
59 win->m_mouseButtonDown = true;
60 return false;
cb43b372 61}
865bb325 62}
cb43b372
RR
63
64//-----------------------------------------------------------------------------
add7cadd 65// "button_release_event" from scrollbar
cb43b372
RR
66//-----------------------------------------------------------------------------
67
865bb325 68extern "C" {
add7cadd
PC
69static gboolean
70gtk_button_release_event(GtkRange*, GdkEventButton*, wxScrollBar* win)
cb43b372 71{
a2615ebc
VZ
72 if (g_isIdle)
73 wxapp_install_idle_handler();
74
add7cadd
PC
75 win->m_mouseButtonDown = false;
76 // If thumb tracking
2a23d363
RR
77 if (win->m_isScrolling)
78 {
add7cadd
PC
79 win->m_isScrolling = false;
80 const int value = win->GetThumbPosition();
81 const int orient = win->HasFlag(wxSB_VERTICAL) ? wxVERTICAL : wxHORIZONTAL;
a2615ebc 82
add7cadd
PC
83 wxScrollEvent event(wxEVT_SCROLL_THUMBRELEASE, win->GetId(), value, orient);
84 event.SetEventObject(win);
85 win->GetEventHandler()->ProcessEvent(event);
a2615ebc 86
add7cadd
PC
87 wxScrollEvent event2(wxEVT_SCROLL_CHANGED, win->GetId(), value, orient);
88 event2.SetEventObject(win);
89 win->GetEventHandler()->ProcessEvent(event2);
90 }
7c2f14ee 91
add7cadd 92 return false;
cb43b372 93}
865bb325 94}
cb43b372 95
b4071e91
RR
96//-----------------------------------------------------------------------------
97// wxScrollBar
98//-----------------------------------------------------------------------------
99
c801d85f
KB
100IMPLEMENT_DYNAMIC_CLASS(wxScrollBar,wxControl)
101
add7cadd
PC
102wxScrollBar::wxScrollBar()
103{
104}
105
0a07a7d8 106wxScrollBar::~wxScrollBar()
c801d85f 107{
6de97a3b 108}
c801d85f 109
debe6624 110bool wxScrollBar::Create(wxWindow *parent, wxWindowID id,
c801d85f 111 const wxPoint& pos, const wxSize& size,
6de97a3b 112 long style, const wxValidator& validator, const wxString& name )
c801d85f 113{
91af0895
WS
114 m_needParent = true;
115 m_acceptsFocus = true;
a2615ebc 116
4dcaf11a
RR
117 if (!PreCreation( parent, pos, size ) ||
118 !CreateBase( parent, id, pos, size, style, validator, name ))
119 {
223d09f6 120 wxFAIL_MSG( wxT("wxScrollBar creation failed") );
91af0895 121 return false;
4dcaf11a 122 }
6de97a3b 123
add7cadd
PC
124 const bool isVertical = (style & wxSB_VERTICAL) != 0;
125 if (isVertical)
2d17d68f 126 m_widget = gtk_vscrollbar_new( (GtkAdjustment *) NULL );
d9bd1494
SB
127 else
128 m_widget = gtk_hscrollbar_new( (GtkAdjustment *) NULL );
129
add7cadd 130 m_scrollBar[int(isVertical)] = (GtkRange*)m_widget;
a2615ebc 131
add7cadd
PC
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);
cb43b372 138
f03fc89f 139 m_parent->DoAddChild( this );
a2615ebc 140
abdeb9e7 141 PostCreation(size);
a2615ebc 142
91af0895 143 return true;
6de97a3b 144}
c801d85f 145
0a07a7d8 146int wxScrollBar::GetThumbPosition() const
c801d85f 147{
add7cadd
PC
148 GtkAdjustment* adj = ((GtkRange*)m_widget)->adjustment;
149 return int(adj->value + 0.5);
6de97a3b 150}
c801d85f
KB
151
152int wxScrollBar::GetThumbSize() const
153{
add7cadd
PC
154 GtkAdjustment* adj = ((GtkRange*)m_widget)->adjustment;
155 return int(adj->page_size);
6de97a3b 156}
c801d85f
KB
157
158int wxScrollBar::GetPageSize() const
159{
add7cadd
PC
160 GtkAdjustment* adj = ((GtkRange*)m_widget)->adjustment;
161 return int(adj->page_increment);
6de97a3b 162}
c801d85f
KB
163
164int wxScrollBar::GetRange() const
165{
add7cadd
PC
166 GtkAdjustment* adj = ((GtkRange*)m_widget)->adjustment;
167 return int(adj->upper);
6de97a3b 168}
c801d85f 169
4fabb575 170void wxScrollBar::SetThumbPosition( int viewStart )
c801d85f 171{
add7cadd 172 if (GetThumbPosition() != viewStart)
2d17d68f 173 {
add7cadd
PC
174 BlockScrollEvent();
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;
2d17d68f 180 }
6de97a3b 181}
c801d85f 182
add7cadd 183void wxScrollBar::SetScrollbar(int position, int thumbSize, int range, int pageSize, bool)
c801d85f 184{
add7cadd
PC
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;
190 BlockScrollEvent();
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;
6de97a3b 195}
c801d85f 196
debe6624 197void wxScrollBar::SetPageSize( int pageLength )
c801d85f 198{
add7cadd 199 SetScrollbar(GetThumbPosition(), GetThumbSize(), GetRange(), pageLength);
6de97a3b 200}
c801d85f 201
add7cadd 202void wxScrollBar::SetRange(int range)
c801d85f 203{
add7cadd 204 SetScrollbar(GetThumbPosition(), GetThumbSize(), range, GetPageSize());
6de97a3b 205}
c801d85f 206
b4071e91
RR
207bool wxScrollBar::IsOwnGtkWindow( GdkWindow *window )
208{
2d17d68f 209 GtkRange *range = GTK_RANGE(m_widget);
68567a96 210 return ( (window == GTK_WIDGET(range)->window) );
b4071e91 211}
58614078 212
9d522606
RD
213// static
214wxVisualAttributes
215wxScrollBar::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
216{
217 return GetDefaultAttributesFromGTKWidget(gtk_vscrollbar_new);
218}
219
de6185e2 220#endif // wxUSE_SCROLLBAR