]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk/scrolbar.cpp
1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
7 // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "scrolbar.h"
16 #include "wx/scrolbar.h"
19 //-----------------------------------------------------------------------------
21 //-----------------------------------------------------------------------------
23 void gtk_scrollbar_callback( GtkWidget
*WXUNUSED(widget
), wxScrollBar
*win
)
26 printf( "OnScroll from " );
27 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
28 printf( win->GetClassInfo()->GetClassName() );
32 if (!win
->HasVMT()) return;
34 float diff
= win
->m_adjust
->value
- win
->m_oldPos
;
35 if (fabs(diff
) < 0.2) return;
39 float line_step
= win
->m_adjust
->step_increment
;
40 float page_step
= win
->m_adjust
->page_increment
;
42 if (fabs(diff
-line_step
) < 0.2) command
= wxEVT_SCROLL_LINEDOWN
;
43 else if (fabs(diff
+line_step
) < 0.2) command
= wxEVT_SCROLL_LINEUP
;
44 else if (fabs(diff
-page_step
) < 0.2) command
= wxEVT_SCROLL_PAGEDOWN
;
45 else if (fabs(diff
+page_step
) < 0.2) command
= wxEVT_SCROLL_PAGEUP
;
46 else command
= wxEVT_SCROLL_THUMBTRACK
;
48 int value
= (int)(win
->m_adjust
->value
+0.5);
50 int orient
= wxHORIZONTAL
;
51 if (win
->GetWindowStyleFlag() & wxSB_VERTICAL
== wxSB_VERTICAL
) orient
= wxHORIZONTAL
;
53 wxScrollEvent
event( command
, win
->GetId(), value
, orient
);
54 event
.SetEventObject( win
);
55 win
->ProcessEvent( event
);
58 wxCommandEvent cevent( wxEVT_COMMAND_SCROLLBAR_UPDATED, win->GetId() );
59 cevent.SetEventObject( win );
60 win->ProcessEvent( cevent );
64 IMPLEMENT_DYNAMIC_CLASS(wxScrollBar
,wxControl
)
66 wxScrollBar::wxScrollBar(wxWindow
*parent
, const wxWindowID id
,
67 const wxPoint
& pos
, const wxSize
& size
,
68 const long style
, const wxString
& name
)
70 Create( parent
, id
, pos
, size
, style
, name
);
73 wxScrollBar::~wxScrollBar(void)
77 bool wxScrollBar::Create(wxWindow
*parent
, const wxWindowID id
,
78 const wxPoint
& pos
, const wxSize
& size
,
79 const long style
, const wxString
& name
)
83 PreCreation( parent
, id
, pos
, size
, style
, name
);
87 if (style
& wxSB_VERTICAL
== wxSB_VERTICAL
)
88 m_widget
= gtk_hscrollbar_new( NULL
);
90 m_widget
= gtk_vscrollbar_new( NULL
);
92 m_adjust
= gtk_range_get_adjustment( GTK_RANGE(m_widget
) );
94 gtk_signal_connect (GTK_OBJECT (m_adjust
), "value_changed",
95 (GtkSignalFunc
) gtk_scrollbar_callback
, (gpointer
) this );
104 int wxScrollBar::GetPosition(void) const
106 return (int)(m_adjust
->value
+0.5);
109 int wxScrollBar::GetThumbSize() const
111 return (int)(m_adjust
->page_size
+0.5);
114 int wxScrollBar::GetPageSize() const
116 return (int)(m_adjust
->page_increment
+0.5);
119 int wxScrollBar::GetRange() const
121 return (int)(m_adjust
->upper
+0.5);
124 void wxScrollBar::SetPosition( const int viewStart
)
126 float fpos
= (float)viewStart
;
128 if (fabs(fpos
-m_adjust
->value
) < 0.2) return;
129 m_adjust
->value
= fpos
;
131 gtk_signal_emit_by_name( GTK_OBJECT(m_adjust
), "value_changed" );
134 void wxScrollBar::SetScrollbar( const int position
, const int thumbSize
, const int range
, const int pageSize
,
135 const bool WXUNUSED(refresh
) )
137 float fpos
= (float)position
;
139 float frange
= (float)range
;
140 float fthumb
= (float)thumbSize
;
141 float fpage
= (float)pageSize
;
143 if ((fabs(fpos
-m_adjust
->value
) < 0.2) &&
144 (fabs(frange
-m_adjust
->upper
) < 0.2) &&
145 (fabs(fthumb
-m_adjust
->page_size
) < 0.2) &&
146 (fabs(fpage
-m_adjust
->page_increment
) < 0.2))
149 m_adjust
->lower
= 0.0;
150 m_adjust
->upper
= frange
;
151 m_adjust
->value
= fpos
;
152 m_adjust
->step_increment
= 1.0;
153 m_adjust
->page_increment
= (float)(wxMax(fpage
-2,0));
154 m_adjust
->page_size
= fthumb
;
156 gtk_signal_emit_by_name( GTK_OBJECT(m_adjust
), "changed" );
159 // Backward compatibility
160 int wxScrollBar::GetValue(void) const
162 return GetPosition();
165 void wxScrollBar::SetValue( const int viewStart
)
167 SetPosition( viewStart
);
170 void wxScrollBar::GetValues( int *viewStart
, int *viewLength
, int *objectLength
, int *pageLength
) const
172 int pos
= (int)(m_adjust
->value
+0.5);
173 int thumb
= (int)(m_adjust
->page_size
+0.5);
174 int page
= (int)(m_adjust
->page_increment
+0.5);
175 int range
= (int)(m_adjust
->upper
+0.5);
179 *objectLength
= thumb
;
183 int wxScrollBar::GetViewLength() const
185 return (int)(m_adjust
->upper
+0.5);
188 int wxScrollBar::GetObjectLength() const
190 return (int)(m_adjust
->page_size
+0.5);
193 void wxScrollBar::SetPageSize( const int pageLength
)
195 int pos
= (int)(m_adjust
->value
+0.5);
196 int thumb
= (int)(m_adjust
->page_size
+0.5);
197 int range
= (int)(m_adjust
->upper
+0.5);
198 SetScrollbar( pos
, thumb
, range
, pageLength
);
201 void wxScrollBar::SetObjectLength( const int objectLength
)
203 int pos
= (int)(m_adjust
->value
+0.5);
204 int page
= (int)(m_adjust
->page_increment
+0.5);
205 int range
= (int)(m_adjust
->upper
+0.5);
206 SetScrollbar( pos
, objectLength
, range
, page
);
209 void wxScrollBar::SetViewLength( const int viewLength
)
211 int pos
= (int)(m_adjust
->value
+0.5);
212 int thumb
= (int)(m_adjust
->page_size
+0.5);
213 int page
= (int)(m_adjust
->page_increment
+0.5);
214 SetScrollbar( pos
, thumb
, viewLength
, page
);