]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk/spinbutt.cpp
86f7f8f5bf7194459ab0edf9b16de493566dc94f
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/spinbutt.cpp
3 // Purpose: wxSpinButton
7 // Copyright: (c) Robert Roebling
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
16 #include "wx/spinbutt.h"
24 //-----------------------------------------------------------------------------
26 //-----------------------------------------------------------------------------
28 extern bool g_blockEventsOnDrag
;
30 //-----------------------------------------------------------------------------
32 //-----------------------------------------------------------------------------
36 gtk_value_changed(GtkSpinButton
* spinbutton
, wxSpinButton
* win
)
38 const double value
= gtk_spin_button_get_value(spinbutton
);
39 const int pos
= int(value
);
40 const int oldPos
= win
->m_pos
;
41 if (!win
->m_hasVMT
|| g_blockEventsOnDrag
|| win
->m_blockScrollEvent
|| pos
== oldPos
)
47 wxSpinEvent
event(pos
> oldPos
? wxEVT_SCROLL_LINEUP
: wxEVT_SCROLL_LINEDOWN
, win
->GetId());
48 event
.SetPosition(pos
);
49 event
.SetEventObject(win
);
51 if ((win
->GetEventHandler()->ProcessEvent( event
)) &&
54 /* program has vetoed */
55 win
->BlockScrollEvent();
56 gtk_spin_button_set_value(spinbutton
, oldPos
);
57 win
->UnblockScrollEvent();
63 /* always send a thumbtrack event */
64 wxSpinEvent
event2(wxEVT_SCROLL_THUMBTRACK
, win
->GetId());
65 event2
.SetPosition(pos
);
66 event2
.SetEventObject(win
);
67 win
->GetEventHandler()->ProcessEvent(event2
);
71 //-----------------------------------------------------------------------------
73 //-----------------------------------------------------------------------------
75 IMPLEMENT_DYNAMIC_CLASS(wxSpinButton
,wxControl
)
76 IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent
, wxNotifyEvent
)
78 BEGIN_EVENT_TABLE(wxSpinButton
, wxControl
)
79 EVT_SIZE(wxSpinButton::OnSize
)
82 wxSpinButton::wxSpinButton()
87 bool wxSpinButton::Create(wxWindow
*parent
,
96 wxSize new_size
= size
,
97 sizeBest
= DoGetBestSize();
98 new_size
.x
= sizeBest
.x
; // override width always
100 new_size
.y
= sizeBest
.y
;
102 if (!PreCreation( parent
, pos
, new_size
) ||
103 !CreateBase( parent
, id
, pos
, new_size
, style
, wxDefaultValidator
, name
))
105 wxFAIL_MSG( wxT("wxSpinButton creation failed") );
111 m_widget
= gtk_spin_button_new_with_range(0, 100, 1);
113 gtk_spin_button_set_wrap( GTK_SPIN_BUTTON(m_widget
),
114 (int)(m_windowStyle
& wxSP_WRAP
) );
116 g_signal_connect_after(
117 m_widget
, "value_changed", G_CALLBACK(gtk_value_changed
), this);
119 m_parent
->DoAddChild( this );
121 PostCreation(new_size
);
126 int wxSpinButton::GetMin() const
128 wxCHECK_MSG( (m_widget
!= NULL
), 0, wxT("invalid spin button") );
131 gtk_spin_button_get_range((GtkSpinButton
*)m_widget
, &min
, NULL
);
135 int wxSpinButton::GetMax() const
137 wxCHECK_MSG( (m_widget
!= NULL
), 0, wxT("invalid spin button") );
140 gtk_spin_button_get_range((GtkSpinButton
*)m_widget
, NULL
, &max
);
144 int wxSpinButton::GetValue() const
146 wxCHECK_MSG( (m_widget
!= NULL
), 0, wxT("invalid spin button") );
151 void wxSpinButton::SetValue( int value
)
153 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid spin button") );
156 gtk_spin_button_set_value((GtkSpinButton
*)m_widget
, value
);
157 UnblockScrollEvent();
160 void wxSpinButton::SetRange(int minVal
, int maxVal
)
162 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid spin button") );
165 gtk_spin_button_set_range((GtkSpinButton
*)m_widget
, minVal
, maxVal
);
166 UnblockScrollEvent();
169 void wxSpinButton::OnSize( wxSizeEvent
&WXUNUSED(event
) )
171 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid spin button") );
173 m_width
= DoGetBestSize().x
;
174 gtk_widget_set_size_request( m_widget
, m_width
, m_height
);
177 GdkWindow
*wxSpinButton::GTKGetWindow(wxArrayGdkWindows
& WXUNUSED(windows
)) const
179 return GTK_SPIN_BUTTON(m_widget
)->panel
;
182 wxSize
wxSpinButton::DoGetBestSize() const
184 wxSize
best(15, 26); // FIXME
191 wxSpinButton::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
193 // TODO: overload to accept functions like gtk_spin_button_new?
194 // Until then use a similar type
195 return GetDefaultAttributesFromGTKWidget(gtk_button_new
);